mirror of https://github.com/sveltejs/svelte
parent
a16704fbf0
commit
9d37ae4f4b
@ -0,0 +1,27 @@
|
|||||||
|
export function appendNode ( node, target ) {
|
||||||
|
target.appendChild( node );
|
||||||
|
}
|
||||||
|
|
||||||
|
export function insertNode ( node, target, anchor ) {
|
||||||
|
target.insertBefore( node, anchor );
|
||||||
|
}
|
||||||
|
|
||||||
|
export function detachNode ( node ) {
|
||||||
|
node.parentNode.removeChild( node );
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createElement ( name ) {
|
||||||
|
return document.createElement( name );
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createSvgElement ( name ) {
|
||||||
|
return document.createElementNS( 'http://www.w3.org/2000/svg', name );
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createText ( data ) {
|
||||||
|
return document.createTextNode( data );
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createComment ( data ) {
|
||||||
|
return document.createComment( data );
|
||||||
|
}
|
@ -1,29 +1,27 @@
|
|||||||
export function noop () {}
|
export * from './dom.js';
|
||||||
|
export * from './methods.js';
|
||||||
|
|
||||||
export function appendNode ( node, target ) {
|
export function noop () {}
|
||||||
target.appendChild( node );
|
|
||||||
}
|
|
||||||
|
|
||||||
export function insertNode ( node, target, anchor ) {
|
export function dispatchObservers ( component, group, newState, oldState ) {
|
||||||
target.insertBefore( node, anchor );
|
for ( var key in group ) {
|
||||||
}
|
if ( !( key in newState ) ) continue;
|
||||||
|
|
||||||
export function detachNode ( node ) {
|
var newValue = newState[ key ];
|
||||||
node.parentNode.removeChild( node );
|
var oldValue = oldState[ key ];
|
||||||
}
|
|
||||||
|
|
||||||
export function createElement ( name ) {
|
if ( newValue === oldValue && typeof newValue !== 'object' ) continue;
|
||||||
return document.createElement( name );
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createSvgElement ( name ) {
|
var callbacks = group[ key ];
|
||||||
return document.createElementNS( 'http://www.w3.org/2000/svg', name );
|
if ( !callbacks ) continue;
|
||||||
}
|
|
||||||
|
|
||||||
export function createText ( data ) {
|
for ( var i = 0; i < callbacks.length; i += 1 ) {
|
||||||
return document.createTextNode( data );
|
var callback = callbacks[i];
|
||||||
}
|
if ( callback.__calling ) continue;
|
||||||
|
|
||||||
export function createComment ( data ) {
|
callback.__calling = true;
|
||||||
return document.createComment( data );
|
callback.call( component, newValue, oldValue );
|
||||||
|
callback.__calling = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
export function get ( key ) {
|
||||||
|
return key ? this._state[ key ] : this._state;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fire ( eventName, data ) {
|
||||||
|
var handlers = eventName in this._handlers && this._handlers[ eventName ].slice();
|
||||||
|
if ( !handlers ) return;
|
||||||
|
|
||||||
|
for ( var i = 0; i < handlers.length; i += 1 ) {
|
||||||
|
handlers[i].call( this, data );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function observe ( key, callback, options ) {
|
||||||
|
var group = ( options && options.defer ) ? this._observers.pre : this._observers.post;
|
||||||
|
|
||||||
|
( group[ key ] || ( group[ key ] = [] ) ).push( callback );
|
||||||
|
|
||||||
|
if ( !options || options.init !== false ) {
|
||||||
|
callback.__calling = true;
|
||||||
|
callback.call( this, this._state[ key ] );
|
||||||
|
callback.__calling = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
cancel: function () {
|
||||||
|
var index = group[ key ].indexOf( callback );
|
||||||
|
if ( ~index ) group[ key ].splice( index, 1 );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function on ( eventName, handler ) {
|
||||||
|
var handlers = this._handlers[ eventName ] || ( this._handlers[ eventName ] = [] );
|
||||||
|
handlers.push( handler );
|
||||||
|
|
||||||
|
return {
|
||||||
|
cancel: function () {
|
||||||
|
var index = handlers.indexOf( handler );
|
||||||
|
if ( ~index ) handlers.splice( index, 1 );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in new issue