|
|
@ -61,14 +61,13 @@ function differs(a, b) {
|
|
|
|
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
|
|
|
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function dispatchObservers(component, group, newState, oldState) {
|
|
|
|
function dispatchObservers(component, group, changed, newState, oldState) {
|
|
|
|
for (var key in group) {
|
|
|
|
for (var key in group) {
|
|
|
|
if (!(key in newState)) continue;
|
|
|
|
if (!changed[key]) continue;
|
|
|
|
|
|
|
|
|
|
|
|
var newValue = newState[key];
|
|
|
|
var newValue = newState[key];
|
|
|
|
var oldValue = oldState[key];
|
|
|
|
var oldValue = oldState[key];
|
|
|
|
|
|
|
|
|
|
|
|
if (differs(newValue, oldValue)) {
|
|
|
|
|
|
|
|
var callbacks = group[key];
|
|
|
|
var callbacks = group[key];
|
|
|
|
if (!callbacks) continue;
|
|
|
|
if (!callbacks) continue;
|
|
|
|
|
|
|
|
|
|
|
@ -81,7 +80,6 @@ function dispatchObservers(component, group, newState, oldState) {
|
|
|
|
callback.__calling = false;
|
|
|
|
callback.__calling = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function get(key) {
|
|
|
|
function get(key) {
|
|
|
@ -143,6 +141,23 @@ function set(newState) {
|
|
|
|
this._root._lock = false;
|
|
|
|
this._root._lock = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _set(newState) {
|
|
|
|
|
|
|
|
var oldState = this._state,
|
|
|
|
|
|
|
|
changed = {},
|
|
|
|
|
|
|
|
dirty = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (var key in newState) {
|
|
|
|
|
|
|
|
if (differs(newState[key], oldState[key])) changed[key] = dirty = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dirty) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this._state = assign({}, oldState, newState);
|
|
|
|
|
|
|
|
this._recompute(changed, this._state, oldState, false);
|
|
|
|
|
|
|
|
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
|
|
|
|
|
|
|
|
this._fragment.update(changed, this._state);
|
|
|
|
|
|
|
|
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function callAll(fns) {
|
|
|
|
function callAll(fns) {
|
|
|
|
while (fns && fns.length) fns.pop()();
|
|
|
|
while (fns && fns.length) fns.pop()();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -154,11 +169,13 @@ var proto = {
|
|
|
|
observe: observe,
|
|
|
|
observe: observe,
|
|
|
|
on: on,
|
|
|
|
on: on,
|
|
|
|
set: set,
|
|
|
|
set: set,
|
|
|
|
teardown: destroy
|
|
|
|
teardown: destroy,
|
|
|
|
|
|
|
|
_recompute: noop,
|
|
|
|
|
|
|
|
_set: _set
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function create_main_fragment ( state, component ) {
|
|
|
|
function create_main_fragment ( state, component ) {
|
|
|
|
var text, p, text_1_value, text_1;
|
|
|
|
var text, p, text_1;
|
|
|
|
|
|
|
|
|
|
|
|
var each_block_value = state.comments;
|
|
|
|
var each_block_value = state.comments;
|
|
|
|
|
|
|
|
|
|
|
@ -176,7 +193,7 @@ function create_main_fragment ( state, component ) {
|
|
|
|
|
|
|
|
|
|
|
|
text = createText( "\n\n" );
|
|
|
|
text = createText( "\n\n" );
|
|
|
|
p = createElement( 'p' );
|
|
|
|
p = createElement( 'p' );
|
|
|
|
text_1 = createText( text_1_value = state.foo );
|
|
|
|
text_1 = createText( state.foo );
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
mount: function ( target, anchor ) {
|
|
|
|
mount: function ( target, anchor ) {
|
|
|
@ -192,7 +209,7 @@ function create_main_fragment ( state, component ) {
|
|
|
|
update: function ( changed, state ) {
|
|
|
|
update: function ( changed, state ) {
|
|
|
|
var each_block_value = state.comments;
|
|
|
|
var each_block_value = state.comments;
|
|
|
|
|
|
|
|
|
|
|
|
if ( 'comments' in changed || 'elapsed' in changed || 'time' in changed ) {
|
|
|
|
if ( changed.comments || changed.elapsed || changed.time ) {
|
|
|
|
for ( var i = 0; i < each_block_value.length; i += 1 ) {
|
|
|
|
for ( var i = 0; i < each_block_value.length; i += 1 ) {
|
|
|
|
if ( each_block_iterations[i] ) {
|
|
|
|
if ( each_block_iterations[i] ) {
|
|
|
|
each_block_iterations[i].update( changed, state, each_block_value, each_block_value[i], i );
|
|
|
|
each_block_iterations[i].update( changed, state, each_block_value, each_block_value[i], i );
|
|
|
@ -210,8 +227,8 @@ function create_main_fragment ( state, component ) {
|
|
|
|
each_block_iterations.length = each_block_value.length;
|
|
|
|
each_block_iterations.length = each_block_value.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( text_1_value !== ( text_1_value = state.foo ) ) {
|
|
|
|
if ( changed.foo ) {
|
|
|
|
text_1.data = text_1_value;
|
|
|
|
text_1.data = state.foo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
@ -231,18 +248,18 @@ function create_main_fragment ( state, component ) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function create_each_block ( state, each_block_value, comment, i, component ) {
|
|
|
|
function create_each_block ( state, each_block_value, comment, i, component ) {
|
|
|
|
var div, strong, text_value, text, text_1, span, text_2_value, text_2, text_3, text_4_value, text_4, text_5, text_6, raw_value, raw_before, raw_after;
|
|
|
|
var div, strong, text, text_1, span, text_2_value = comment.author, text_2, text_3, text_4_value = state.elapsed(comment.time, state.time), text_4, text_5, text_6, raw_value = comment.html, raw_before, raw_after;
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
create: function () {
|
|
|
|
create: function () {
|
|
|
|
div = createElement( 'div' );
|
|
|
|
div = createElement( 'div' );
|
|
|
|
strong = createElement( 'strong' );
|
|
|
|
strong = createElement( 'strong' );
|
|
|
|
text = createText( text_value = i );
|
|
|
|
text = createText( i );
|
|
|
|
text_1 = createText( "\n\n\t\t" );
|
|
|
|
text_1 = createText( "\n\n\t\t" );
|
|
|
|
span = createElement( 'span' );
|
|
|
|
span = createElement( 'span' );
|
|
|
|
text_2 = createText( text_2_value = comment.author );
|
|
|
|
text_2 = createText( text_2_value );
|
|
|
|
text_3 = createText( " wrote " );
|
|
|
|
text_3 = createText( " wrote " );
|
|
|
|
text_4 = createText( text_4_value = state.elapsed(comment.time, state.time) );
|
|
|
|
text_4 = createText( text_4_value );
|
|
|
|
text_5 = createText( " ago:" );
|
|
|
|
text_5 = createText( " ago:" );
|
|
|
|
text_6 = createText( "\n\n\t\t" );
|
|
|
|
text_6 = createText( "\n\n\t\t" );
|
|
|
|
raw_before = createElement( 'noscript' );
|
|
|
|
raw_before = createElement( 'noscript' );
|
|
|
@ -268,25 +285,21 @@ function create_each_block ( state, each_block_value, comment, i, component ) {
|
|
|
|
appendNode( text_6, div );
|
|
|
|
appendNode( text_6, div );
|
|
|
|
appendNode( raw_before, div );
|
|
|
|
appendNode( raw_before, div );
|
|
|
|
appendNode( raw_after, div );
|
|
|
|
appendNode( raw_after, div );
|
|
|
|
raw_before.insertAdjacentHTML( 'afterend', raw_value = comment.html );
|
|
|
|
raw_before.insertAdjacentHTML( 'afterend', raw_value );
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
update: function ( changed, state, each_block_value, comment, i ) {
|
|
|
|
update: function ( changed, state, each_block_value, comment, i ) {
|
|
|
|
if ( text_value !== ( text_value = i ) ) {
|
|
|
|
if ( ( changed.comments ) && text_2_value !== ( text_2_value = comment.author ) ) {
|
|
|
|
text.data = text_value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( text_2_value !== ( text_2_value = comment.author ) ) {
|
|
|
|
|
|
|
|
text_2.data = text_2_value;
|
|
|
|
text_2.data = text_2_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( text_4_value !== ( text_4_value = state.elapsed(comment.time, state.time) ) ) {
|
|
|
|
if ( ( changed.elapsed || changed.comments || changed.time ) && text_4_value !== ( text_4_value = state.elapsed(comment.time, state.time) ) ) {
|
|
|
|
text_4.data = text_4_value;
|
|
|
|
text_4.data = text_4_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( raw_value !== ( raw_value = comment.html ) ) {
|
|
|
|
if ( ( changed.comments ) && raw_value !== ( raw_value = comment.html ) ) {
|
|
|
|
detachBetween( raw_before, raw_after );
|
|
|
|
detachBetween( raw_before, raw_after );
|
|
|
|
raw_before.insertAdjacentHTML( 'afterend', raw_value = comment.html );
|
|
|
|
raw_before.insertAdjacentHTML( 'afterend', raw_value );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
@ -324,12 +337,4 @@ function SvelteComponent ( options ) {
|
|
|
|
|
|
|
|
|
|
|
|
assign( SvelteComponent.prototype, proto );
|
|
|
|
assign( SvelteComponent.prototype, proto );
|
|
|
|
|
|
|
|
|
|
|
|
SvelteComponent.prototype._set = function _set ( newState ) {
|
|
|
|
|
|
|
|
var oldState = this._state;
|
|
|
|
|
|
|
|
this._state = assign( {}, oldState, newState );
|
|
|
|
|
|
|
|
dispatchObservers( this, this._observers.pre, newState, oldState );
|
|
|
|
|
|
|
|
this._fragment.update( newState, this._state );
|
|
|
|
|
|
|
|
dispatchObservers( this, this._observers.post, newState, oldState );
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default SvelteComponent;
|
|
|
|
export default SvelteComponent;
|
|
|
|