Migrate more components to use mixin

This commit is contained in:
Paulus Schoutsen 2015-02-14 00:11:23 -08:00
parent 791ebff7ee
commit dcffd102cc
2 changed files with 26 additions and 22 deletions
homeassistant/components/frontend/www_static/polymer

View file

@ -30,20 +30,25 @@
</template>
<script>
Polymer({
loaded: window.hass.syncStore.initialLoadDone(),
var storeListenerMixIn = window.hass.storeListenerMixIn;
Polymer(Polymer.mixin({
loaded: false,
ready: function() {
// remove the HTML init message
document.getElementById('init').remove();
// listen if we are fully loaded
window.hass.syncStore.addChangeListener(this.updateLoadStatus.bind(this));
this.listenToStores(true);
},
updateLoadStatus: function() {
this.loaded = window.hass.syncStore.initialLoadDone();
detached: function() {
this.stopListeningToStores();
},
});
syncStoreChanged: function(syncStore) {
this.loaded = syncStore.initialLoadDone();
},
}, storeListenerMixIn));
</script>
</polymer-element>

View file

@ -31,32 +31,31 @@
</partial-base>
</template>
<script>
Polymer({
var storeListenerMixIn = window.hass.storeListenerMixIn;
var stateHistoryActions = window.hass.stateHistoryActions;
Polymer(Polymer.mixin({
stateHistory: null,
ready: function() {
this.stateHistoryStoreChanged = this.stateHistoryStoreChanged.bind(this);
window.hass.stateHistoryStore.addChangeListener(this.stateHistoryStoreChanged);
if (window.hass.stateHistoryStore.isStale()) {
window.hass.stateHistoryActions.fetchAll();
}
this.stateHistoryStoreChanged();
this.listenToStores(true);
},
detached: function() {
window.hass.stateHistoryStore.removeChangeListener(this.stateHistoryStoreChanged);
this.stopListeningToStores();
},
stateHistoryStoreChanged: function() {
this.stateHistory = window.hass.stateHistoryStore.all();
stateHistoryStoreChanged: function(stateHistoryStore) {
if (stateHistoryStore.isStale()) {
stateHistoryActions.fetchAll();
}
this.stateHistory = stateHistoryStore.all();
},
handleRefreshClick: function() {
window.hass.stateHistoryActions.fetchAll();
stateHistoryActions.fetchAll();
},
});
}, storeListenerMixIn));
</script>
</polymer>