-
Notifications
You must be signed in to change notification settings - Fork 1
/
ford-app-redux.html
86 lines (79 loc) · 2.07 KB
/
ford-app-redux.html
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="demo/redux-mixin.html">
<dom-module id="ford-app-redux">
<template>
<style>
:host {
display: block;
}
#backgroundSection {
width:100px;
height:100px;
}
</style>
<h3>Redux - [[bkgroundcolor]] </h3>
<div class="section">
<div style$="background-color:[[bkgroundcolor]]"id="backgroundSection"></div>
<button on-click="changeColor" data-color="green">Green</button>
<button on-click="changeColor" data-color="blue">Blue</button>
<button on-click="changeColor" data-color="red">Red</button>
</div>
</template>
<script>
/**
* `ford-app-redux`
*
*
* @customElement
* @polymer
* @demo demo/index.html
*/
class FordAppRedux extends ReduxMixin(Polymer.Element) {
static get is() { return 'ford-app-redux'; }
static get properties() {
return {
bkgroundcolor: {
type: String,
statePath(state) {
return state.bkcolor;
}
},
bkgroundcolors: {
type: String,
value: 'green'
}
};
}
static get actions() {
return {
changeColorState(bkColor) {
switch(bkColor) {
case 'green':
return {
type: 'BKGROUND_COLOR_GREEN'
};
case 'blue':
return {
type: 'BKGROUND_COLOR_BLUE'
};
case 'red':
return {
type: 'BKGROUND_COLOR_RED'
};
}
}
};
}
changeColor(e) {
this.dispatch('changeColorState',e.target.dataset.color);
}
connectedCallback() {
super.connectedCallback();
setTimeout(() => {
this.dispatch('changeColorState', 'blue');
}, 2000);
}
}
window.customElements.define(FordAppRedux.is, FordAppRedux);
</script>
</dom-module>