Remove trailing whitespace

This commit is contained in:
impinball 2015-07-09 03:34:41 -04:00
parent 34020b1f23
commit d4848c0379
3 changed files with 57 additions and 57 deletions

View file

@ -122,4 +122,4 @@ where:
- **Boolean forceRecreation** - **Boolean forceRecreation**
If set to true, rendering a new virtual tree will completely overwrite an existing one without attempting to diff against it If set to true, rendering a new virtual tree will completely overwrite an existing one without attempting to diff against it

2
mithril.d.ts vendored
View file

@ -17,7 +17,7 @@ declare module _mithril {
mount<T extends MithrilController>(rootElement: Node): T; mount<T extends MithrilController>(rootElement: Node): T;
component<T extends MithrilController>(component: MithrilComponent<T>, ...args: Array<any>): MithrilComponent<T> component<T extends MithrilController>(component: MithrilComponent<T>, ...args: Array<any>): MithrilComponent<T>
trust(html: string): string; trust(html: string): string;
render(rootElement: Element|HTMLDocument): void; render(rootElement: Element|HTMLDocument): void;

View file

@ -7,10 +7,10 @@ var mod = ( function initModulator(){
var Map = shim; var Map = shim;
var WeakMap = shim; var WeakMap = shim;
} }
// Garbage collection flag // Garbage collection flag
mod.cleanup = true; mod.cleanup = true;
// Registry of instantiation contexts // Registry of instantiation contexts
var contexts = new WeakMap(); var contexts = new WeakMap();
// All automated counts // All automated counts
@ -20,36 +20,36 @@ var mod = ( function initModulator(){
var snapRedraw = m.redraw; var snapRedraw = m.redraw;
var redraw; var redraw;
var forced; var forced;
for( var key in m.redraw ){ for( var key in m.redraw ){
queueRedraw[ key ] = snapRedraw[ key ] = m.redraw[ key ]; queueRedraw[ key ] = snapRedraw[ key ] = m.redraw[ key ];
} }
return function pause(){ return function pause(){
m.redraw = queueRedraw; m.redraw = queueRedraw;
setTimeout( function unpause(){ setTimeout( function unpause(){
m.redraw = snapRedraw; m.redraw = snapRedraw;
if( redraw ) m.redraw( forced ); if( redraw ) m.redraw( forced );
redraw = forced = false; redraw = forced = false;
} ); } );
} }
function queueRedraw( force ){ function queueRedraw( force ){
redraw = true; redraw = true;
if( force ) forced = true; if( force ) forced = true;
} }
}() ); }() );
var unique = {}; var unique = {};
// Clear counts at the begninning of every redraw // Clear counts at the begninning of every redraw
m.module( document.createElement( 'x' ), { m.module( document.createElement( 'x' ), {
view : counts.clear.bind( counts ) view : counts.clear.bind( counts )
} ); } );
// Shorthand for a component which will always return the same instance // Shorthand for a component which will always return the same instance
mod.unique = function( component ){ mod.unique = function( component ){
return mod( component, unique, unique ); return mod( component, unique, unique );
@ -58,80 +58,80 @@ var mod = ( function initModulator(){
mod.global = function( x ){ mod.global = function( x ){
return mod( x, unique ); return mod( x, unique );
}; };
// Extend controllers with extra utility functions // Extend controllers with extra utility functions
mod.extend = true; mod.extend = true;
return mod; return mod;
function mod( component, context, key ){ function mod( component, context, key ){
// Stand in for m.module, eg mod( document.body, component, context ); // Stand in for m.module, eg mod( document.body, component, context );
if( component instanceof HTMLElement ){ if( component instanceof HTMLElement ){
// Stand in for m.route // Stand in for m.route
if( !component.controller && !component.view ){ if( !component.controller && !component.view ){
var routes = {}; var routes = {};
for( var route in context ){ for( var route in context ){
routes[ route ].controller = mod.unique( { routes[ route ].controller = mod.unique( {
controller : context[ route ].controller || noop controller : context[ route ].controller || noop
} ).bind(); } ).bind();
} }
return m.route( component, routes ); return m.route( component, routes );
} }
return m.module( component, mod.apply( undefined, [].slice.call( arguments, 1 ) ) )(); return m.module( component, mod.apply( undefined, [].slice.call( arguments, 1 ) ) )();
} }
var components = register( contexts, context || unique, WeakMap ); var components = register( contexts, context || unique, WeakMap );
var keys = register( components, component, WeakMap ); var keys = register( components, component, WeakMap );
return function identify( key ){ return function identify( key ){
var count = key === undefined && register( counts, keys, m.prop.bind( undefined, 0 ) ); var count = key === undefined && register( counts, keys, m.prop.bind( undefined, 0 ) );
// eg. ctrl.mod( profile ).mapWith( users(), 'username' ); // eg. ctrl.mod( profile ).mapWith( users(), 'username' );
apply.mapWith = function( collection ){ apply.mapWith = function( collection ){
var path = [].slice.call( arguments, 1 ); var path = [].slice.call( arguments, 1 );
return Object.keys( collection ).map( function getItemIdentifier( index ){ return Object.keys( collection ).map( function getItemIdentifier( index ){
var key; var key;
if( path.length ){ if( path.length ){
key = path.reduce( function getKeyValue( source, segment ){ key = path.reduce( function getKeyValue( source, segment ){
var node = source[ segment ]; var node = source[ segment ];
if( node instanceof Function ) node = node.call( source ); if( node instanceof Function ) node = node.call( source );
return node; return node;
}, collection[ index ] ); }, collection[ index ] );
} }
else { else {
key = index; key = index;
} }
return identify( key )( collection[ index ] ); return identify( key )( collection[ index ] );
} ); } );
}; };
return apply; return apply;
function apply(){ function apply(){
var args = [].slice.call( arguments ); var args = [].slice.call( arguments );
var view; var view;
if( count ){ if( count ){
key = count( count() + 1 ); key = count( count() + 1 );
} }
var ctrl = register( keys, key, function newController(){ var ctrl = register( keys, key, function newController(){
pauseRedraw(); pauseRedraw();
var controller = component.controller || noop; var controller = component.controller || noop;
var instance = new ( controller.bind.apply( controller, [ controller ].concat( args ) ) )(); var instance = new ( controller.bind.apply( controller, [ controller ].concat( args ) ) )();
if( mod.cleanup ){ if( mod.cleanup ){
garbageCollect( instance ); garbageCollect( instance );
} }
if( mod.extend ){ if( mod.extend ){
// Shorthand for instantiatin sub-modules // Shorthand for instantiatin sub-modules
instance.mod = function( component, key ){ instance.mod = function( component, key ){
@ -145,14 +145,14 @@ var mod = ( function initModulator(){
instance.refresh = function(){ instance.refresh = function(){
args = [].slice.call( arguments ); args = [].slice.call( arguments );
ctrl = register( keys, key, newController, true ); ctrl = register( keys, key, newController, true );
return m.redraw; return m.redraw;
}; };
} }
return instance; return instance;
} ); } );
// Return the controller instance if the component is view-less. // Return the controller instance if the component is view-less.
if( component.view ){ if( component.view ){
if( args.length ){ if( args.length ){
@ -161,31 +161,31 @@ var mod = ( function initModulator(){
else { else {
view = component.view( ctrl ); view = component.view( ctrl );
} }
if( view instanceof Object ){ if( view instanceof Object ){
view.ctrl = ctrl; view.ctrl = ctrl;
} }
return view; return view;
} }
return ctrl; return ctrl;
} }
}( key ); }( key );
// Performance: when controllers succesfully unload, destroy their associated maps // Performance: when controllers succesfully unload, destroy their associated maps
function garbageCollect( ctrl ){ function garbageCollect( ctrl ){
onunload = ctrl.onunload; onunload = ctrl.onunload;
if( onunload === teardown ){ if( onunload === teardown ){
return; return;
} }
ctrl.onunload = teardown; ctrl.onunload = teardown;
function teardown( e ){ function teardown( e ){
var go = true; var go = true;
if( onunload ){ if( onunload ){
onunload( { onunload( {
preventDefault : function(){ preventDefault : function(){
@ -193,39 +193,39 @@ var mod = ( function initModulator(){
} }
} ); } );
} }
if( go ){ if( go ){
contexts.delete( context ); contexts.delete( context );
} }
} }
} }
} }
// Convenience map method: retrieve key from map. If it's not registered, set it first with Constructor. // Convenience map method: retrieve key from map. If it's not registered, set it first with Constructor.
function register( map, key, Constructor, force ){ function register( map, key, Constructor, force ){
return !force && map.has( key ) ? map.get( key ) : map.set( key, new Constructor() ).get( key ); return !force && map.has( key ) ? map.get( key ) : map.set( key, new Constructor() ).get( key );
} }
function shim(){ function shim(){
var keys = []; var keys = [];
var values = []; var values = [];
var map = { var map = {
get : function( key ){ get : function( key ){
var index = keys.indexOf( key ); var index = keys.indexOf( key );
return values[ index ]; return values[ index ];
}, },
has : function( key ){ has : function( key ){
var index = keys.indexOf( key ); var index = keys.indexOf( key );
return index > -1; return index > -1;
}, },
set : function( key, value ){ set : function( key, value ){
var index = map.has( key ) ? keys.indexOf( key ) : keys.length; var index = map.has( key ) ? keys.indexOf( key ) : keys.length;
keys[ index ] = key; keys[ index ] = key;
values[ index ] = value; values[ index ] = value;
return map; return map;
}, },
clear : function(){ clear : function(){
@ -234,21 +234,21 @@ var mod = ( function initModulator(){
}, },
delete : function( key ){ delete : function( key ){
var index = keys.indexOf( key ); var index = keys.indexOf( key );
if( index > -1 ){ if( index > -1 ){
keys.splice( index, 1 ); keys.splice( index, 1 );
values.splice( index, 1 ); values.splice( index, 1 );
return true; return true;
} }
return false; return false;
} }
}; };
return map; return map;
} }
function noop(){} function noop(){}
}() ); }() );
</script> </script>
@ -271,4 +271,4 @@ b.view = function(ctrl, count) {
return m("li", count) return m("li", count)
} }
m.module(document.body, a)</script> m.module(document.body, a)</script>