|
|
@ -238,7 +238,7 @@ export default function generate ( parsed, source, options ) {
|
|
|
|
const topLevelStatements = [];
|
|
|
|
const topLevelStatements = [];
|
|
|
|
|
|
|
|
|
|
|
|
const setStatements = [ deindent`
|
|
|
|
const setStatements = [ deindent`
|
|
|
|
const oldState = state;
|
|
|
|
var oldState = state;
|
|
|
|
state = Object.assign( {}, oldState, newState );
|
|
|
|
state = Object.assign( {}, oldState, newState );
|
|
|
|
` ];
|
|
|
|
` ];
|
|
|
|
|
|
|
|
|
|
|
@ -392,19 +392,19 @@ export default function generate ( parsed, source, options ) {
|
|
|
|
var callbacks = Object.create( null );
|
|
|
|
var callbacks = Object.create( null );
|
|
|
|
|
|
|
|
|
|
|
|
function dispatchObservers ( group, newState, oldState ) {
|
|
|
|
function dispatchObservers ( group, newState, oldState ) {
|
|
|
|
for ( const key in group ) {
|
|
|
|
for ( var key in group ) {
|
|
|
|
if ( !( key in newState ) ) continue;
|
|
|
|
if ( !( key in newState ) ) continue;
|
|
|
|
|
|
|
|
|
|
|
|
const newValue = newState[ key ];
|
|
|
|
var newValue = newState[ key ];
|
|
|
|
const oldValue = oldState[ key ];
|
|
|
|
var oldValue = oldState[ key ];
|
|
|
|
|
|
|
|
|
|
|
|
if ( newValue === oldValue && typeof newValue !== 'object' ) continue;
|
|
|
|
if ( newValue === oldValue && typeof newValue !== 'object' ) continue;
|
|
|
|
|
|
|
|
|
|
|
|
const callbacks = group[ key ];
|
|
|
|
var callbacks = group[ key ];
|
|
|
|
if ( !callbacks ) continue;
|
|
|
|
if ( !callbacks ) continue;
|
|
|
|
|
|
|
|
|
|
|
|
for ( let i = 0; i < callbacks.length; i += 1 ) {
|
|
|
|
for ( var i = 0; i < callbacks.length; i += 1 ) {
|
|
|
|
const callback = callbacks[i];
|
|
|
|
var callback = callbacks[i];
|
|
|
|
if ( callback.__calling ) continue;
|
|
|
|
if ( callback.__calling ) continue;
|
|
|
|
|
|
|
|
|
|
|
|
callback.__calling = true;
|
|
|
|
callback.__calling = true;
|
|
|
@ -431,32 +431,32 @@ export default function generate ( parsed, source, options ) {
|
|
|
|
${setStatements.join( '\n\n' )}
|
|
|
|
${setStatements.join( '\n\n' )}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.observe = function ( key, callback, options = {} ) {
|
|
|
|
this.observe = function ( key, callback, options ) {
|
|
|
|
const group = options.defer ? observers.deferred : observers.immediate;
|
|
|
|
var group = ( options && options.defer ) ? observers.deferred : observers.immediate;
|
|
|
|
|
|
|
|
|
|
|
|
( group[ key ] || ( group[ key ] = [] ) ).push( callback );
|
|
|
|
( group[ key ] || ( group[ key ] = [] ) ).push( callback );
|
|
|
|
|
|
|
|
|
|
|
|
if ( options.init !== false ) {
|
|
|
|
if ( !options || options.init !== false ) {
|
|
|
|
callback.__calling = true;
|
|
|
|
callback.__calling = true;
|
|
|
|
callback.call( component, state[ key ] );
|
|
|
|
callback.call( component, state[ key ] );
|
|
|
|
callback.__calling = false;
|
|
|
|
callback.__calling = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
cancel () {
|
|
|
|
cancel: function () {
|
|
|
|
const index = group[ key ].indexOf( callback );
|
|
|
|
var index = group[ key ].indexOf( callback );
|
|
|
|
if ( ~index ) group[ key ].splice( index, 1 );
|
|
|
|
if ( ~index ) group[ key ].splice( index, 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.on = function on ( eventName, handler ) {
|
|
|
|
this.on = function on ( eventName, handler ) {
|
|
|
|
const handlers = callbacks[ eventName ] || ( callbacks[ eventName ] = [] );
|
|
|
|
var handlers = callbacks[ eventName ] || ( callbacks[ eventName ] = [] );
|
|
|
|
handlers.push( handler );
|
|
|
|
handlers.push( handler );
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
cancel: function () {
|
|
|
|
cancel: function () {
|
|
|
|
const index = handlers.indexOf( handler );
|
|
|
|
var index = handlers.indexOf( handler );
|
|
|
|
if ( ~index ) handlers.splice( index, 1 );
|
|
|
|
if ( ~index ) handlers.splice( index, 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|