blob: 0dee7eea8fe5d6eaf8fc908f596ff7f799d299ad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/**
@license
Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
import { html } from '@polymer/lit-element';
import { PageViewElement } from './page-view-element.js';
import { connect } from 'pwa-helpers/connect-mixin.js';
// This element is connected to the Redux store.
import { store } from '../store.js';
// These are the actions needed by this element.
import { increment, decrement } from '../actions/counter.js';
// We are lazy loading its reducer.
import counter from '../reducers/counter.js';
store.addReducers({
counter
});
// These are the elements needed by this element.
import './counter-element.js';
// These are the shared styles needed by this element.
import { SharedStyles } from './shared-styles.js';
class MyView2 extends connect(store)(PageViewElement) {
_render(props) {
return html`
${SharedStyles}
<section>
<h2>Redux example: simple counter</h2>
<div class="circle">${props._value}</div>
<p>This page contains a reusable <code><counter-element></code>. The
element is not built in a Redux-y way (you can think of it as being a
third-party element you got from someone else), but this page is connected to the
Redux store. When the element updates its counter, this page updates the values
in the Redux store, and you can see the current value of the counter reflected in
the bubble above.</p>
<br><br>
</section>
<section>
<p>
<counter-element value="${props._value}" clicks="${props._clicks}"
on-counter-incremented="${() => store.dispatch(increment())}"
on-counter-decremented="${() => store.dispatch(decrement())}">
</counter-element>
</p>
</section>
`;
}
static get properties() { return {
// This is the data from the store.
_clicks: Number,
_value: Number
}}
// This is called every time something is updated in the store.
_stateChanged(state) {
this._clicks = state.counter.clicks;
this._value = state.counter.value;
}
}
window.customElements.define('my-view2', MyView2);
|