Skip to content

Commit

Permalink
better this._super
Browse files Browse the repository at this point in the history
  • Loading branch information
martypdx committed Jun 15, 2014
1 parent 8c220dc commit 513146f
Show file tree
Hide file tree
Showing 16 changed files with 575 additions and 238 deletions.
34 changes: 34 additions & 0 deletions ractive-model.md
@@ -0,0 +1,34 @@
## instance
* debug
* isolated

## viewmodel
* data
* computed
* adapt, adaptors
* magic

# view
* components
* template, partials

### parser
* parseOptions

### binding
* two-way, lazy

### dom
* el, append

* events
* decorators

#### animation & style
* transitions
* easing
* interpolators
* css
* noIntro, transitionsEnabled
* noCssTransform

5 changes: 3 additions & 2 deletions src/Ractive/initialise.js
Expand Up @@ -9,15 +9,16 @@ export default function initialiseRactiveInstance ( ractive, options = {} ) {

initialiseProperties( ractive, options );


// init config from Parent and options
config.init( ractive.constructor, ractive, options );

// TEMPORARY. This is so we can implement Viewmodel gradually
ractive.viewmodel = new Viewmodel( ractive );


// hacky circular problem until we get this sorted out
// if viewmodel immediately processes computed properties,
// they may call ractive.get, which calls ractive.viewmodel,
// which hasn't been set till line above finishes.
ractive.viewmodel.compute();

// Render our *root fragment*
Expand Down
76 changes: 14 additions & 62 deletions src/config/config.js
Expand Up @@ -2,23 +2,21 @@ import css from 'config/options/css/css';
import data from 'config/options/data';
import debug from 'config/options/debug';
import defaults from 'config/defaults/options';
import complete from 'config/options/complete';
import computed from 'config/options/computed';
import template from 'config/options/template/template';

import parseOptions from 'config/options/groups/parseOptions';
import registries from 'config/options/groups/registries';

import wrap from 'utils/wrapPrototypeMethod';
import deprecate from 'config/deprecate';

import warn from 'utils/warn';
import isArray from 'utils/isArray';

var custom, options, config;

custom = {
data: data,
debug: debug,
complete: complete,
computed: computed,
template: template,
css: css
Expand All @@ -37,7 +35,6 @@ config = [].concat(
custom.data,
parseOptions,
options,
custom.complete,
custom.computed,
registries,
custom.template,
Expand All @@ -55,55 +52,6 @@ config.parseOptions = parseOptions;
config.registries = registries;


function getMessage( deprecated, isError ) {
return 'ractive.' + deprecated + ' has been deprecated in favour of ractive.events.' +
isError ? ' You cannot specify both options, please use ractive.events.' : '';
}

function deprecate ( options, deprecated, correct ) {

// TODO remove support
if ( deprecated in options ) {

if( !( correct in options ) ) {

warn( getMessage( deprecated ) );

options[ correct ] = options[ deprecated ];

}
else {

throw new Error( getMessage( deprecated, true ) );

}

}
}

function deprecateEventDefinitions ( options ) {

deprecate( options, 'eventDefinitions', 'events' );
}

function depricateAdaptors ( options ) {

// Using extend with Component instead of options,
// like Human.extend( Spider ) means adaptors as a registry
// gets copied to options. So we have to check if actually an array
if ( 'adaptors' in options && isArray( options.adaptors ) ) {

deprecate( options, 'adaptors', 'adapt' );

}

}

function deprecateOptions ( options ) {
deprecateEventDefinitions( options );
depricateAdaptors( options );
}

function customConfig ( method, key, Parent, instance, options ) {
custom[ key ][ method ]( Parent, instance, options );
}
Expand All @@ -121,16 +69,15 @@ config.init = function ( Parent, ractive, options ) {
ractive._config.options = options;
}

// would be nice to not have to do this.
// currently for init method
config.keys.forEach( key => {
options[ key ] = ractive[ key ];
});
// Breaking change
// config.keys.forEach( key => {
// options[ key ] = ractive[ key ];
// });
};

function configure ( method, Parent, instance, options ) {

deprecateOptions( options );
deprecate( options );

customConfig( method, 'data', Parent, instance, options );
customConfig( method, 'debug', Parent, instance, options );
Expand All @@ -145,11 +92,14 @@ function configure ( method, Parent, instance, options ) {

for ( let key in options ) {
if( key in defaults && !( key in config.parseOptions ) && !( key in custom ) ) {
instance[ key ] = options[ key ];
let value = options[ key ];
instance[ key ] = typeof value === 'function'
? wrap( instance, Parent.prototype, key, value )
: value;
}
}

customConfig( method, 'complete', Parent, instance, options );
// customConfig( method, 'complete', Parent, instance, options );
customConfig( method, 'computed', Parent, instance, options );

config.registries.forEach( registry => {
Expand All @@ -167,6 +117,8 @@ config.reset = function ( ractive ) {
});
};



export default config;


Expand Down
53 changes: 53 additions & 0 deletions src/config/deprecate.js
@@ -0,0 +1,53 @@

import warn from 'utils/warn';
import isArray from 'utils/isArray';


function deprecate ( options, deprecated, correct ) {

if ( deprecated in options ) {

if( !( correct in options ) ) {

warn( getMessage( deprecated, correct ) );

options[ correct ] = options[ deprecated ];

}
else {

throw new Error( getMessage( deprecated, correct, true ) );

}

}
}

function getMessage( deprecated, correct, isError ) {
return 'options.' + deprecated + ' has been deprecated in favour of options.' + correct + '.'
+ ( isError ? ' You cannot specify both options, please use options.' + correct + '.' : '' );
}


function deprecateEventDefinitions ( options ) {

deprecate( options, 'eventDefinitions', 'events' );
}

function depricateAdaptors ( options ) {

// Using extend with Component instead of options,
// like Human.extend( Spider ) means adaptors as a registry
// gets copied to options. So we have to check if actually an array
if ( isArray( options.adaptors ) ) {

deprecate( options, 'adaptors', 'adapt' );

}

}

export default function deprecateOptions ( options ) {
deprecateEventDefinitions( options );
depricateAdaptors( options );
}
14 changes: 2 additions & 12 deletions src/config/options/baseConfiguration.js
Expand Up @@ -35,22 +35,12 @@ BaseConfiguration.prototype = {

extend: function ( Parent, proto, options ) {

this.configure( Parent, proto, options,
// temp
this.name,
this.preExtend ? this.preExtend.bind(this) : void 0,
this.postExtend ? this.postExtend.bind(this) : void 0
);
this.configure( Parent, proto, options );
},

init: function ( Parent, ractive, options ) {

this.configure( Parent, ractive, options,
// temp
this.name,
this.preInit ? this.preInit.bind(this) : void 0,
this.postInit ? this.postInit.bind(this) : void 0
);
this.configure( Parent, ractive, options );
},

reset: function ( ractive ) {
Expand Down
27 changes: 0 additions & 27 deletions src/config/options/complete.js

This file was deleted.

22 changes: 9 additions & 13 deletions src/config/options/computed.js
Expand Up @@ -4,22 +4,16 @@ var computed = {
name: 'computed',
extend: function ( Parent, child, options ) {

var name = this.name, registry, option = options[ name ];

Parent = Parent.defaults;

registry = create( Parent[name] );


for( let key in option ) {
registry[ key ] = option[ key ];
}

child[ name ] = registry;
this.configure( Parent, child, options );

},
init: function ( Parent, ractive, options ) {

this.configure( Parent, ractive, options );
},

configure: function ( Parent, instance, options ) {

var name = this.name, registry, option = options[ name ];

Parent = Parent.defaults;
Expand All @@ -31,8 +25,10 @@ var computed = {
registry[ key ] = option[ key ];
}

ractive[ name ] = registry;
instance[ name ] = registry;
}

};


export default computed;
22 changes: 9 additions & 13 deletions src/config/options/registry.js
Expand Up @@ -7,6 +7,7 @@ export default function registryConfig ( config ) {
config = extendObject( config, {
extend: extend,
init: init,
configure: configure,
find: find,
findInstance: findInstance
});
Expand All @@ -17,23 +18,18 @@ export default function registryConfig ( config ) {

function extend ( Parent, proto, options ) {

var name = this.name,
option = options[ name ],
Child = proto.constructor,
registry = create( Parent[name] );
this.configure( Parent, proto.constructor, options );

}

for( let key in option ) {
registry[ key ] = option[ key ];
}

if ( this.post ) { registry = this.post( proto, registry ); }
function init ( Parent, ractive, options ) {

Child[ name ] = registry;
this.configure( Parent, ractive, options );

}

function init ( Parent, ractive, options ) {

function configure ( Parent, target, options ) {

var name = this.name,
option = options[ name ],
Expand All @@ -44,9 +40,9 @@ function init ( Parent, ractive, options ) {
registry[ key ] = option[ key ];
}

if ( this.post ) { registry = this.post( ractive, registry ); }
if ( this.post ) { registry = this.post( target, registry ); }

ractive[ name ] = registry;
target[ name ] = registry;

}

Expand Down

0 comments on commit 513146f

Please sign in to comment.