remove ES2015+ from store.js

pull/954/head
Rich Harris 7 years ago
parent adc248f639
commit 7779f26f7f

@ -19,9 +19,6 @@ function Store(state) {
} }
assign(Store.prototype, { assign(Store.prototype, {
get,
observe
}, {
_add: function(component, props) { _add: function(component, props) {
this._dependents.push({ this._dependents.push({
component: component, component: component,
@ -31,7 +28,7 @@ assign(Store.prototype, {
_init: function(props) { _init: function(props) {
var state = {}; var state = {};
for (let i = 0; i < props.length; i += 1) { for (var i = 0; i < props.length; i += 1) {
var prop = props[i]; var prop = props[i];
state['$' + prop] = this._state[prop]; state['$' + prop] = this._state[prop];
} }
@ -39,7 +36,7 @@ assign(Store.prototype, {
}, },
_remove: function(component) { _remove: function(component) {
let i = this._dependents.length; var i = this._dependents.length;
while (i--) { while (i--) {
if (this._dependents[i].component === component) { if (this._dependents[i].component === component) {
this._dependents.splice(i, 1); this._dependents.splice(i, 1);
@ -48,7 +45,7 @@ assign(Store.prototype, {
} }
}, },
_sortComputedProperties() { _sortComputedProperties: function() {
var computed = this._computed; var computed = this._computed;
var sorted = this._sortedComputedProperties = []; var sorted = this._sortedComputedProperties = [];
var visited = blankObject(); var visited = blankObject();
@ -95,6 +92,10 @@ assign(Store.prototype, {
this._sortComputedProperties(); this._sortComputedProperties();
}, },
get: get,
observe: observe,
onchange: function(callback) { onchange: function(callback) {
this._changeHandlers.push(callback); this._changeHandlers.push(callback);
return { return {
@ -153,11 +154,11 @@ function combineStores(children, store) {
if (!store) store = new Store(); if (!store) store = new Store();
var updates = {}; var updates = {};
for (const key in children) { for (var key in children) {
const child = children[key]; var child = children[key];
updates[key] = child.get(); updates[key] = child.get();
child.onchange(state => { child.onchange(function(state) {
var update = {}; var update = {};
update[key] = state; update[key] = state;
store.set(update); store.set(update);

Loading…
Cancel
Save