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

View File

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

View File

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