More conversion to ES2015

This commit is contained in:
Paulus Schoutsen 2015-07-14 22:32:19 -07:00
parent b395e3b4db
commit 7a86b86745
26 changed files with 63 additions and 104 deletions

View File

@ -20,7 +20,6 @@ export default Polymer({
}, },
ready() { ready() {
this.forceStateChange = this.forceStateChange.bind(this);
this.forceStateChange(); this.forceStateChange();
}, },
@ -57,7 +56,7 @@ export default Polymer({
// with the state. It will be out of sync if our service call did not // with the state. It will be out of sync if our service call did not
// result in the entity to be turned on. Since the state is not changing, // result in the entity to be turned on. Since the state is not changing,
// the resync is not called automatic. // the resync is not called automatic.
serviceActions.callTurnOn(this.stateObj.entityId).then(this.forceStateChange); serviceActions.callTurnOn(this.stateObj.entityId).then(() => this.forceStateChange());
}, },
turn_off() { turn_off() {
@ -65,6 +64,6 @@ export default Polymer({
// with the state. It will be out of sync if our service call did not // with the state. It will be out of sync if our service call did not
// result in the entity to be turned on. Since the state is not changing, // result in the entity to be turned on. Since the state is not changing,
// the resync is not called automatic. // the resync is not called automatic.
serviceActions.callTurnOff(this.stateObj.entityId).then(this.forceStateChange); serviceActions.callTurnOff(this.stateObj.entityId).then(() => this.forceStateChange());
}, },
}); });

View File

@ -19,7 +19,6 @@ export default Polymer({
cardTapped(ev) { cardTapped(ev) {
ev.stopPropagation(); ev.stopPropagation();
this.async(moreInfoActions.selectEntity.bind( this.async(() => moreInfoActions.selectEntity(this.stateObj.entityId), 100);
this, this.stateObj.entityId), 100);
}, },
}); });

View File

@ -11,7 +11,7 @@ export default Polymer({
}, },
}, },
computeTime: function(dateObj) { computeTime(dateObj) {
return dateObj ? formatTime(dateObj) : ''; return dateObj ? formatTime(dateObj) : '';
}, },
}); });

View File

@ -13,16 +13,12 @@ export default Polymer({
type: Array, type: Array,
bindNuclear: [ bindNuclear: [
entityGetters.entityMap, entityGetters.entityMap,
function(map) { (map) => map.valueSeq().sortBy((entity) => entity.entityId).toArray()
return map.valueSeq().
sortBy(function(entity) { return entity.entityId; })
.toArray();
},
], ],
}, },
}, },
entitySelected: function(ev) { entitySelected(ev) {
ev.preventDefault(); ev.preventDefault();
this.fire('entity-selected', {entityId: ev.model.entity.entityId}); this.fire('entity-selected', {entityId: ev.model.entity.entityId});
}, },

View File

@ -13,11 +13,7 @@ export default Polymer({
type: Array, type: Array,
bindNuclear: [ bindNuclear: [
eventGetters.entityMap, eventGetters.entityMap,
function(map) { (map) => map.valueSeq().sortBy((event) => event.event).toArray()
return map.valueSeq()
.sortBy(function(event) { return event.event; })
.toArray();
}
], ],
}, },
}, },

View File

@ -78,8 +78,7 @@ export default Polymer({
if (this.mouseMoveIsThrottled) { if (this.mouseMoveIsThrottled) {
this.mouseMoveIsThrottled = false; this.mouseMoveIsThrottled = false;
this.onColorSelect(e); this.onColorSelect(e);
this.async( this.async(() => this.mouseMoveIsThrottled = true, 100);
function() { this.mouseMoveIsThrottled = true; }.bind(this), 100);
} }
}, },

View File

@ -12,7 +12,7 @@ Polymer({
}, },
}, },
noEntries: function(entries) { noEntries(entries) {
return !entries.length; return !entries.length;
} }
}); });

View File

@ -36,7 +36,7 @@ Polymer({
value: [], value: [],
bindNuclear: [ bindNuclear: [
navigationGetters.possibleEntityDomainFilters, navigationGetters.possibleEntityDomainFilters,
function(domains) { return domains.toArray(); } (domains) => domains.toArray()
], ],
}, },

View File

@ -15,11 +15,7 @@ export default Polymer({
type: Array, type: Array,
bindNuclear: [ bindNuclear: [
serviceGetters.entityMap, serviceGetters.entityMap,
function(map) { (map) => map.valueSeq().sortBy((domain) => domain.domain).toJS()
return map.valueSeq()
.sortBy(function(domain) { return domain.domain; })
.toJS();
},
], ],
}, },
}, },

View File

@ -30,15 +30,15 @@ export default Polymer({
}, },
}, },
created: function() { created() {
this.style.display = 'block'; this.style.display = 'block';
}, },
attached: function() { attached() {
this.isAttached = true; this.isAttached = true;
}, },
dataChanged: function() { dataChanged() {
this.drawChart(); this.drawChart();
}, },
@ -115,11 +115,7 @@ export default Polymer({
// Get a unique list of times of state changes for all the device // Get a unique list of times of state changes for all the device
// for a particular unit of measureent. // for a particular unit of measureent.
var times = pluck(flatten(deviceStates), "lastChangedAsDate"); var times = pluck(flatten(deviceStates), "lastChangedAsDate");
times = uniq(times, function(e) { times = sortBy(uniq(times, (e) => e.getTime()));
return e.getTime();
});
times = sortBy(times, function(o) { return o; });
var data = []; var data = [];
var empty = new Array(deviceStates.length); var empty = new Array(deviceStates.length);
@ -143,9 +139,8 @@ export default Polymer({
} }
data.push([endDate].concat(empty)); data.push([endDate].concat(empty));
var deviceCount = 0; var deviceCount = 0;
deviceStates.forEach(function(device) { deviceStates.forEach((device) => {
var attributes = device[device.length - 1].attributes; var attributes = device[device.length - 1].attributes;
dataTable.addColumn('number', attributes.friendly_name); dataTable.addColumn('number', attributes.friendly_name);
@ -154,7 +149,7 @@ export default Polymer({
var lastIndex = 0; var lastIndex = 0;
var count = 0; var count = 0;
var prevTime = data[0][0]; var prevTime = data[0][0];
device.forEach(function(state) { device.forEach((state) => {
currentState = state.state; currentState = state.state;
var start = state.lastChangedAsDate; var start = state.lastChangedAsDate;
@ -178,7 +173,7 @@ export default Polymer({
previousState = currentState; previousState = currentState;
count++; count++;
}.bind(this)); });
//fill in the rest of the Array //fill in the rest of the Array
for(var i = lastIndex; i < data.length; i++) { for(var i = lastIndex; i < data.length; i++) {
@ -186,7 +181,7 @@ export default Polymer({
} }
deviceCount++; deviceCount++;
}.bind(this)); });
dataTable.addRows(data); dataTable.addRows(data);
chart.draw(dataTable, options); chart.draw(dataTable, options);

View File

@ -53,10 +53,8 @@ export default Polymer({
}; };
var startTime = new Date( var startTime = new Date(
stateHistory.reduce(function(minTime, stateInfo) { stateHistory.reduce((minTime, stateInfo) => Math.min(
return Math.min( minTime, stateInfo[0].lastChangedAsDate), new Date())
minTime, stateInfo[0].lastChangedAsDate);
}, new Date())
); );
// end time is Math.min(curTime, start time + 1 day) // end time is Math.min(curTime, start time + 1 day)
@ -68,13 +66,13 @@ export default Polymer({
var numTimelines = 0; var numTimelines = 0;
// stateHistory is a list of lists of sorted state objects // stateHistory is a list of lists of sorted state objects
stateHistory.forEach(function(stateInfo) { stateHistory.forEach((stateInfo) => {
if(stateInfo.length === 0) return; if(stateInfo.length === 0) return;
var entityDisplay = stateInfo[0].entityDisplay; var entityDisplay = stateInfo[0].entityDisplay;
var newLastChanged, prevState = null, prevLastChanged = null; var newLastChanged, prevState = null, prevLastChanged = null;
stateInfo.forEach(function(state) { stateInfo.forEach((state) => {
if (prevState !== null && state.state !== prevState) { if (prevState !== null && state.state !== prevState) {
newLastChanged = state.lastChangedAsDate; newLastChanged = state.lastChangedAsDate;
@ -90,7 +88,7 @@ export default Polymer({
addRow(entityDisplay, prevState, prevLastChanged, endTime); addRow(entityDisplay, prevState, prevLastChanged, endTime);
numTimelines++; numTimelines++;
}.bind(this)); });
chart.draw(dataTable, { chart.draw(dataTable, {
height: 55 + numTimelines * 42, height: 55 + numTimelines * 42,

View File

@ -50,14 +50,13 @@ export default Polymer({
var lineChartDevices = {}; var lineChartDevices = {};
var timelineDevices = []; var timelineDevices = [];
stateHistory.forEach(function(stateInfo) { stateHistory.forEach((stateInfo) => {
if (!stateInfo || stateInfo.size === 0) { if (!stateInfo || stateInfo.size === 0) {
return; return;
} }
var stateWithUnit = stateInfo.find(function(state) { var stateWithUnit = stateInfo.find(
return 'unit_of_measurement' in state.attributes; (state) => 'unit_of_measurement' in state.attributes);
});
var unit = stateWithUnit ? var unit = stateWithUnit ?
stateWithUnit.attributes.unit_of_measurement : false; stateWithUnit.attributes.unit_of_measurement : false;
@ -73,8 +72,8 @@ export default Polymer({
timelineDevices = timelineDevices.length > 0 && timelineDevices; timelineDevices = timelineDevices.length > 0 && timelineDevices;
var unitStates = Object.keys(lineChartDevices).map(function(unit) { var unitStates = Object.keys(lineChartDevices).map(
return [unit, lineChartDevices[unit]]; }); (unit) => [unit, lineChartDevices[unit]]);
return {line: unitStates, timeline: timelineDevices}; return {line: unitStates, timeline: timelineDevices};
}, },
@ -82,9 +81,7 @@ export default Polymer({
googleApiLoaded() { googleApiLoaded() {
google.load("visualization", "1", { google.load("visualization", "1", {
packages: ["timeline", "corechart"], packages: ["timeline", "corechart"],
callback: function() { callback: () => this.apiLoaded = true
this.apiLoaded = true;
}.bind(this)
}); });
}, },

View File

@ -32,9 +32,7 @@ export default Polymer({
type: Object, type: Object,
bindNuclear: [ bindNuclear: [
moreInfoGetters.currentEntityHistory, moreInfoGetters.currentEntityHistory,
function(history) { (history) => history ? [history] : false
return history ? [history] : false;
},
], ],
}, },
@ -92,9 +90,7 @@ export default Polymer({
// allow dialog to render content before showing it so it is // allow dialog to render content before showing it so it is
// positioned correctly. // positioned correctly.
this.async(function() { this.async(() => this.dialogOpen = true, 10);
this.dialogOpen = true;
}.bind(this), 10);
}, },
dialogOpenChanged(newVal) { dialogOpenChanged(newVal) {

View File

@ -45,7 +45,7 @@ export default Polymer({
isValidatingChanged: function(newVal) { isValidatingChanged: function(newVal) {
if (!newVal) { if (!newVal) {
this.async(function() { this.$.passwordInput.focus(); }.bind(this), 10); this.async(() => this.$.passwordInput.focus(), 10);
} }
}, },

View File

@ -39,7 +39,7 @@ export default Polymer({
type: Array, type: Array,
bindNuclear: [ bindNuclear: [
logbookGetters.currentEntries, logbookGetters.currentEntries,
function(entries) { return entries.toArray(); }, (entries) => entries.toArray(),
], ],
}, },
@ -51,8 +51,7 @@ export default Polymer({
isStaleChanged(newVal) { isStaleChanged(newVal) {
if (newVal) { if (newVal) {
// isLoading wouldn't update without async <_< // isLoading wouldn't update without async <_<
this.async( this.async(() => logbookActions.fetchDate(this.selectedDate), 10);
function() { logbookActions.fetchDate(this.selectedDate); }, 10);
} }
}, },

View File

@ -50,9 +50,7 @@ export default Polymer({
bindNuclear: [ bindNuclear: [
voiceGetters.isVoiceSupported, voiceGetters.isVoiceSupported,
configGetters.isComponentLoaded('conversation'), configGetters.isComponentLoaded('conversation'),
function(isVoiceSupported, componentLoaded) { (isVoiceSupported, componentLoaded) => isVoiceSupported && componentLoaded
return isVoiceSupported && componentLoaded;
}
] ]
}, },
@ -66,9 +64,7 @@ export default Polymer({
bindNuclear: [ bindNuclear: [
voiceGetters.isListening, voiceGetters.isListening,
voiceGetters.isTransmitting, voiceGetters.isTransmitting,
function(isListening, isTransmitting) { (isListening, isTransmitting) => isListening || isTransmitting
return isListening || isTransmitting;
},
], ],
}, },
@ -79,7 +75,7 @@ export default Polymer({
// are here so a change to services causes a re-render. // are here so a change to services causes a re-render.
// we need this to decide if we show toggles for states. // we need this to decide if we show toggles for states.
serviceGetters.entityMap, serviceGetters.entityMap,
function(states) { return states.toArray(); }, (states) => states.toArray(),
], ],
}, },
}, },

View File

@ -61,16 +61,16 @@ export default Polymer({
}; };
serviceActions.callService('configurator', 'configure', data).then( serviceActions.callService('configurator', 'configure', data).then(
function() { () => {
this.isConfiguring = false; this.isConfiguring = false;
if (!this.isStreaming) { if (!this.isStreaming) {
syncActions.fetchAll(); syncActions.fetchAll();
} }
}.bind(this), },
() => {
function() {
this.isConfiguring = false; this.isConfiguring = false;
}.bind(this)); }
);
}, },
}); });

View File

@ -16,9 +16,7 @@ export default Polymer({
return []; return [];
} }
return Object.keys(stateObj.attributes).filter(function(key) { return Object.keys(stateObj.attributes).filter((key) => FILTER_KEYS.indexOf(key) === -1);
return FILTER_KEYS.indexOf(key) === -1;
});
}, },
getAttributeValue(stateObj, attribute) { getAttributeValue(stateObj, attribute) {

View File

@ -23,7 +23,7 @@ export default Polymer({
bindNuclear: [ bindNuclear: [
moreInfoGetters.currentEntity, moreInfoGetters.currentEntity,
entityGetters.entityMap, entityGetters.entityMap,
function(currentEntity, entities) { (currentEntity, entities) => {
// weird bug?? // weird bug??
if (!currentEntity) { if (!currentEntity) {
return; return;

View File

@ -27,9 +27,7 @@ export default Polymer({
this.brightnessSliderValue = newVal.attributes.brightness; this.brightnessSliderValue = newVal.attributes.brightness;
} }
this.async(function() { this.async(() => this.fire('iron-resize'), 500);
this.fire('iron-resize');
}.bind(this), 500);
}, },
computeClassNames(stateObj) { computeClassNames(stateObj) {

View File

@ -86,7 +86,7 @@ export default Polymer({
this.supportsTurnOff = (newVal.attributes.supported_media_commands & 256) !== 0; this.supportsTurnOff = (newVal.attributes.supported_media_commands & 256) !== 0;
} }
this.async(function() { this.fire('iron-resize'); }.bind(this), 500); this.async(() => this.fire('iron-resize'), 500);
}, },
computeClassNames(stateObj) { computeClassNames(stateObj) {

View File

@ -78,10 +78,8 @@ export default Polymer({
// the resync is not called automatic. // the resync is not called automatic.
serviceActions.callService( serviceActions.callService(
'thermostat', 'set_away_mode', 'thermostat', 'set_away_mode',
{entity_id: this.stateObj.entityId, away_mode: away_mode}) { away_mode, entity_id: this.stateObj.entityId })
.then(function() { .then(() => this.stateObjChanged(this.stateObj));
this.stateObjChanged(this.stateObj);
}.bind(this));
}, },
}); });

View File

@ -10,11 +10,11 @@ export default Polymer({
}, },
}, },
updateTapped: function(stateObj) { updateTapped(stateObj) {
serviceActions.callService('updater', 'update', {}) serviceActions.callService('updater', 'update', {})
}, },
linkTapped: function(stateObj) { linkTapped(stateObj) {
window.open(this.stateObj.attributes.link, '_blank'); window.open(this.stateObj.attributes.link, '_blank');
}, },
}); });

View File

@ -1,6 +1,6 @@
export default function attributeClassNames(stateObj, attributes) { export default function attributeClassNames(stateObj, attributes) {
if (!stateObj) return ''; if (!stateObj) return '';
return attributes.map(function(attribute) { return attributes.map(
return attribute in stateObj.attributes ? 'has-' + attribute : ''; (attribute) => attribute in stateObj.attributes ? 'has-' + attribute : ''
}).join(' '); ).join(' ');
} }

View File

@ -2,25 +2,24 @@ export default function NuclearObserver(reactor) {
return { return {
attached: function() { attached: function() {
var component = this; this.__unwatchFns = Object.keys(this.properties).reduce(
this.__unwatchFns = Object.keys(component.properties).reduce( (unwatchFns, key) => {
function(unwatchFns, key) { if (!('bindNuclear' in this.properties[key])) {
if (!('bindNuclear' in component.properties[key])) {
return unwatchFns; return unwatchFns;
} }
var getter = component.properties[key].bindNuclear; var getter = this.properties[key].bindNuclear;
if (!getter) { if (!getter) {
throw 'Undefined getter specified for key ' + key; throw 'Undefined getter specified for key ' + key;
} }
component[key] = reactor.evaluate(getter); this[key] = reactor.evaluate(getter);
return unwatchFns.concat(reactor.observe(getter, function(val) { return unwatchFns.concat(reactor.observe(getter, (val) => {
if (__DEV__) { if (__DEV__) {
console.log(component, key, val); console.log(this, key, val);
} }
component[key] = val; this[key] = val;
})); }));
}, []); }, []);
}, },