Comparing version 0.1.3-alpha to 0.1.4-alpha
{ | ||
"name": "imvvm", | ||
"version": "0.1.3-alpha", | ||
"version": "0.1.4-alpha", | ||
"homepage": "https://github.com/entrendipity/imvvm", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -7,17 +7,3 @@ !function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.IMVVM=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | ||
module.exports = IMVVM; | ||
},{"./src/imvvm.js":2}],2:[function(_dereq_,module,exports){ | ||
'use strict' | ||
var base = _dereq_('./imvvmModelBase'); | ||
var mixin = _dereq_('./imvvmMixin'); | ||
var IMVVM = { | ||
createModel: base.createModel, | ||
createViewModel: base.createViewModel, | ||
createAppViewModel: base.createAppViewModel, | ||
imvvmMixin: mixin | ||
}; | ||
module.exports = IMVVM; | ||
},{"./imvvmMixin":4,"./imvvmModelBase":5}],3:[function(_dereq_,module,exports){ | ||
},{"./src/imvvm.js":3}],2:[function(_dereq_,module,exports){ | ||
/*jshint quotmark:false */ | ||
@@ -32,3 +18,3 @@ /*jshint white:false */ | ||
exports.Main = function(appNamespace, appViewModel, initArgs, dataContexts, stateChangedHandler, noUndo) { | ||
exports.getInitialState = function(appNamespace, appViewModel, initArgs, dataContexts, stateChangedHandler, noUndo) { | ||
@@ -44,15 +30,2 @@ if(typeof stateChangedHandler !== 'function'){ | ||
watchList = {}; | ||
// var extend = function () { | ||
// var newObj = {}; | ||
// for (var i = 0; i < arguments.length; i++) { | ||
// var obj = arguments[i]; | ||
// for (var key in obj) { | ||
// if (obj.hasOwnProperty(key)) { | ||
// newObj[key] = obj[key]; | ||
// } | ||
// } | ||
// } | ||
// return newObj; | ||
// }; | ||
@@ -206,42 +179,17 @@ var transitionState = function(nextState, prevState, watchedDataContext){ | ||
}; | ||
},{"./utils":6}],4:[function(_dereq_,module,exports){ | ||
/*jshint quotmark:false */ | ||
/*jshint white:false */ | ||
/*jshint trailing:false */ | ||
/*jshint newcap:false */ | ||
},{"./utils":9}],3:[function(_dereq_,module,exports){ | ||
'use strict' | ||
'use strict'; | ||
var base = _dereq_('./imvvmBase'); | ||
var mixin = _dereq_('./mixin'); | ||
var imvvm = _dereq_('./imvvmMain'); | ||
var NAMESPACE = '__IMVVM__'; | ||
var mixin = { | ||
stateChangedHandler: function(dataContext, callback){ | ||
this.setState({appContext: dataContext}, function(){ | ||
//send all state back to caller | ||
//useful if you need to know what other parts of the app | ||
//were impacted by your changes. You can also use the returned | ||
//information to display things external to your ApplicationModel | ||
//Allows you to have multiple Application ViewModels in the one app and | ||
//still share the state with other presentation models that may be interested | ||
if(typeof callback === 'function'){ | ||
if(this.state !== null && ('appContext' in this.state)){ | ||
callback(this.state.appContext); | ||
} else { | ||
callback(void 0); | ||
} | ||
} | ||
}.bind(this)); | ||
}, | ||
getInitialState: function(){ | ||
var appDataContext = imvvm.Main(NAMESPACE, this.props.viewModel, this.props.initArgs, | ||
this.props.dataContexts, this.stateChangedHandler, this.props.noUndo); | ||
return {appContext: appDataContext}; | ||
} | ||
var IMVVM = { | ||
createModel: base.createModel, | ||
createViewModel: base.createViewModel, | ||
createAppViewModel: base.createAppViewModel, | ||
mixin: mixin | ||
}; | ||
module.exports = mixin; | ||
},{"./imvvmMain":3}],5:[function(_dereq_,module,exports){ | ||
module.exports = IMVVM; | ||
},{"./imvvmBase":5,"./mixin":8}],4:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
@@ -251,165 +199,40 @@ | ||
var extend = utils.extend; | ||
var mixInto = utils.mixInto; | ||
var getDescriptor = utils.getDescriptor; | ||
var IMVVMBase = function() {}; | ||
/*get extend and mixInto from React lib*/ | ||
// var extend = function () { | ||
// var newObj = {}; | ||
// for (var i = 0; i < arguments.length; i++) { | ||
// var obj = arguments[i]; | ||
// for (var key in obj) { | ||
// if (obj.hasOwnProperty(key)) { | ||
// newObj[key] = obj[key]; | ||
// } | ||
// } | ||
// } | ||
// return newObj; | ||
// }; | ||
// var mixInto = function(constructor, methodBag) { | ||
// var methodName; | ||
// for (methodName in methodBag) { | ||
// if (!methodBag.hasOwnProperty(methodName)) { | ||
// continue; | ||
// } | ||
// constructor.prototype[methodName] = methodBag[methodName]; | ||
// } | ||
// }; | ||
var IMVVMModel = { | ||
var IMVVMAppViewModel = { | ||
Mixin: { | ||
construct: function(raiseStateChangeHandler){ | ||
var key, descriptor = {}; | ||
var proto = this.prototype; | ||
var Model = this.classType === 'Model'; | ||
var ViewModel = this.classType === 'ViewModel'; | ||
var AppViewModel = this.classType === 'AppViewModel'; | ||
var originalSpec = this.originalSpec || {}; | ||
for(key in this.originalSpec){ | ||
if(this.originalSpec.hasOwnProperty(key)){ | ||
if('get' in this.originalSpec[key] || 'set' in this.originalSpec[key]){ | ||
//assume it is a descriptor | ||
if(!('enumerable' in this.originalSpec[key])){ | ||
//default enumerable to true | ||
this.originalSpec[key].enumerable = true; | ||
} | ||
descriptor[key] = this.originalSpec[key]; | ||
} else { | ||
proto[key] = this.originalSpec[key]; | ||
} | ||
var desc = getDescriptor.call(this); | ||
desc.proto.setState = raiseStateChangeHandler; | ||
var dataContext = function(state, previousState, oldState) { | ||
state = state || {}; | ||
if(!!previousState){ | ||
Object.defineProperty(state, 'previousState', { | ||
configurable: false, | ||
enumerable: true, | ||
writable: false, | ||
value: previousState | ||
}); | ||
} | ||
} | ||
if(!Model){ | ||
proto.setState = raiseStateChangeHandler; | ||
} | ||
proto.extend = extend; | ||
var dataContext = function(state, withContext, oldState) { | ||
if(ViewModel){ | ||
proto.DataContext = dataContext; | ||
if(!('init' in proto)){ | ||
proto.init = function(){ | ||
return this.DataContext(); | ||
} | ||
} | ||
//Do this after previousState is set so that it is included | ||
if(desc.originalSpec.getInitialState){ | ||
state = extend(state, desc.originalSpec.getInitialState(state, previousState ? previousState.state: void 0)); | ||
} | ||
if(AppViewModel){ | ||
proto.DataContext = function(newState, callback, initialize){ | ||
return proto.setState(newState, callback, true); | ||
} | ||
if(!('init' in proto)){ | ||
proto.init = function(){ | ||
return this.DataContext(); | ||
} | ||
} | ||
desc.proto.DataContext = function(newState, callback, initialize){ | ||
return desc.proto.setState(newState, callback, true); | ||
} | ||
var model = Object.create(proto, descriptor); | ||
if(Model){ | ||
var argCount = arguments.length; | ||
var lastIsBoolean = typeof Array.prototype.slice.call(arguments, -1)[0] === 'boolean'; | ||
if(argCount === 1){ | ||
if(lastIsBoolean){ | ||
withContext = state; | ||
state = {}; | ||
} else { | ||
//state = state || {}; | ||
withContext = true; | ||
} | ||
} else if(argCount === 2){ | ||
if(!lastIsBoolean){ | ||
oldState = withContext; | ||
withContext = true; | ||
} | ||
} else if(argCount === 3){ | ||
if(lastIsBoolean){ | ||
var temp = withContext; | ||
withContext = oldState; | ||
oldState = temp; | ||
} | ||
} else { | ||
state = {}; | ||
withContext = true; | ||
} | ||
if(originalSpec.getInitialState){ | ||
state = extend(state, originalSpec.getInitialState(state, oldState)); | ||
} | ||
if(withContext){ | ||
//This will self distruct | ||
Object.defineProperty(model, 'context', { | ||
configurable: true, | ||
enumerable: true, | ||
set: function(context){ | ||
this.setState = raiseStateChangeHandler(context); | ||
delete this.context; | ||
} | ||
}); | ||
if(!('init' in desc.proto)){ | ||
desc.proto.init = function(){ | ||
return this.DataContext(); | ||
} | ||
} else { | ||
state = state || {}; | ||
if(ViewModel){ | ||
state = extend(state, withContext); | ||
if(originalSpec.getInitialState){ | ||
state = extend(state, originalSpec.getInitialState(state, oldState)); | ||
} | ||
Object.defineProperty(model, 'state', { | ||
configurable: false, | ||
enumerable: false, | ||
writable: false, | ||
value: state | ||
}); | ||
Object.keys(model).map(function(key){ | ||
if(Object.prototype.toString.call(this[key]) === '[object Object]' && | ||
('context' in this[key])){ | ||
this[key].context = this; | ||
Object.freeze(this[key]); | ||
} | ||
}.bind(model)); | ||
state.__proto__ = model.__proto__; | ||
return Object.freeze(state); | ||
} else { //Assume it is AppViewModel | ||
if(!!withContext){ | ||
Object.defineProperty(state, 'previousState', { | ||
configurable: false, | ||
enumerable: true, | ||
writable: false, | ||
value: withContext | ||
}); | ||
} | ||
//Do this after previousState is set so that it is included | ||
if(originalSpec.getInitialState){ | ||
state = extend(state, originalSpec.getInitialState(state, withContext ? withContext.state: void 0)); | ||
} | ||
//set this last | ||
//TODO - rework this, as __proto__ is deprecated | ||
state.__proto__ = model.__proto__; | ||
} | ||
} | ||
var model = Object.create(desc.proto, desc.descriptor); | ||
//set this last | ||
//TODO - rework this, as __proto__ is deprecated | ||
state.__proto__ = model.__proto__; | ||
@@ -423,3 +246,3 @@ Object.defineProperty(model, 'state', { | ||
return model; | ||
}.bind(this); | ||
}; | ||
return dataContext; | ||
@@ -430,9 +253,28 @@ } | ||
mixInto(IMVVMBase, IMVVMModel.Mixin); | ||
module.exports = IMVVMAppViewModel; | ||
},{"./utils":9}],5:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
var utils = _dereq_('./utils'); | ||
var extend = utils.extend; | ||
var mixInto = utils.mixInto; | ||
var model = _dereq_('./imvvmModel'); | ||
var viewModel = _dereq_('./imvvmViewModel'); | ||
var appViewModel = _dereq_('./imvvmAppViewModel'); | ||
var ModelBase = function() {}; | ||
var ViewModelBase = function() {}; | ||
var AppViewModelBase = function() {}; | ||
mixInto(ModelBase, model.Mixin); | ||
mixInto(ViewModelBase, viewModel.Mixin); | ||
mixInto(AppViewModelBase, appViewModel.Mixin); | ||
var IMVVMClass = { | ||
createClass: function(classType, spec){ | ||
createClass: function(ctor, classType, spec){ | ||
var Constructor = function(){}; | ||
Constructor.prototype = new IMVVMBase(); | ||
Constructor.prototype = new ctor(); | ||
Constructor.prototype.constructor = Constructor; | ||
@@ -482,14 +324,208 @@ | ||
}; | ||
var IMVVM = { | ||
createModel: IMVVMClass.createClass.bind(this, 'Model'), | ||
createViewModel: IMVVMClass.createClass.bind(this, 'ViewModel'), | ||
createAppViewModel: IMVVMClass.createClass.bind(this, 'AppViewModel') | ||
var IMVVMConstructors = { | ||
createModel: IMVVMClass.createClass.bind(this, ModelBase, 'Model'), | ||
createViewModel: IMVVMClass.createClass.bind(this, ViewModelBase, 'ViewModel'), | ||
createAppViewModel: IMVVMClass.createClass.bind(this, AppViewModelBase, 'AppViewModel') | ||
}; | ||
module.exports = IMVVM; | ||
module.exports = IMVVMConstructors; | ||
},{"./utils":6}],6:[function(_dereq_,module,exports){ | ||
},{"./imvvmAppViewModel":4,"./imvvmModel":6,"./imvvmViewModel":7,"./utils":9}],6:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
var utils = _dereq_('./utils'); | ||
var extend = utils.extend; | ||
var getDescriptor = utils.getDescriptor; | ||
var IMVVMModel = { | ||
Mixin: { | ||
construct: function(raiseStateChangeHandler){ | ||
var desc = getDescriptor.call(this); | ||
var dataContext = function(state, withContext, oldState) { | ||
var model = Object.create(desc.proto, desc.descriptor); | ||
var argCount = arguments.length; | ||
var lastIsBoolean = typeof Array.prototype.slice.call(arguments, -1)[0] === 'boolean'; | ||
if(argCount === 1){ | ||
if(lastIsBoolean){ | ||
withContext = state; | ||
state = {}; | ||
} else { | ||
//state = state || {}; | ||
withContext = true; | ||
} | ||
} else if(argCount === 2){ | ||
if(!lastIsBoolean){ | ||
oldState = withContext; | ||
withContext = true; | ||
} | ||
} else if(argCount === 3){ | ||
if(lastIsBoolean){ | ||
var temp = withContext; | ||
withContext = oldState; | ||
oldState = temp; | ||
} | ||
} else { | ||
state = {}; | ||
withContext = true; | ||
} | ||
if(desc.originalSpec.getInitialState){ | ||
state = extend(state, desc.originalSpec.getInitialState(state, oldState)); | ||
} | ||
if(withContext){ | ||
//This will self distruct | ||
Object.defineProperty(model, 'context', { | ||
configurable: true, | ||
enumerable: true, | ||
set: function(context){ | ||
this.setState = raiseStateChangeHandler(context); | ||
delete this.context; | ||
} | ||
}); | ||
} | ||
Object.defineProperty(model, 'state', { | ||
configurable: false, | ||
enumerable: false, | ||
writable: false, | ||
value: state | ||
}); | ||
return model; | ||
}; | ||
return dataContext; | ||
} | ||
} | ||
}; | ||
module.exports = IMVVMModel; | ||
},{"./utils":9}],7:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
var utils = _dereq_('./utils'); | ||
var extend = utils.extend; | ||
var getDescriptor = utils.getDescriptor; | ||
var IMVVMViewModel = { | ||
Mixin: { | ||
construct: function(raiseStateChangeHandler){ | ||
var desc = getDescriptor.call(this); | ||
desc.proto.setState = raiseStateChangeHandler; | ||
var dataContext = function(state, dependencies, oldState) { | ||
state = state || {}; | ||
state = extend(state, dependencies); | ||
if(desc.originalSpec.getInitialState){ | ||
state = extend(state, desc.originalSpec.getInitialState(state, oldState)); | ||
} | ||
desc.proto.DataContext = dataContext; | ||
if(!('init' in desc.proto)){ | ||
desc.proto.init = function(){ | ||
return this.DataContext(); | ||
} | ||
} | ||
var model = Object.create(desc.proto, desc.descriptor); | ||
Object.defineProperty(model, 'state', { | ||
configurable: false, | ||
enumerable: false, | ||
writable: false, | ||
value: state | ||
}); | ||
Object.keys(model).map(function(key){ | ||
if(Object.prototype.toString.call(this[key]) === '[object Object]' && | ||
('context' in this[key])){ | ||
this[key].context = this; | ||
Object.freeze(this[key]); | ||
} | ||
}.bind(model)); | ||
state.__proto__ = model.__proto__; | ||
return Object.freeze(state); | ||
}; | ||
return dataContext; | ||
} | ||
} | ||
}; | ||
module.exports = IMVVMViewModel; | ||
},{"./utils":9}],8:[function(_dereq_,module,exports){ | ||
/*jshint quotmark:false */ | ||
/*jshint white:false */ | ||
/*jshint trailing:false */ | ||
/*jshint newcap:false */ | ||
'use strict'; | ||
var core = _dereq_('./core'); | ||
var NAMESPACE = '__IMVVM__'; | ||
var mixin = { | ||
stateChangedHandler: function(dataContext, callback){ | ||
this.setState({appContext: dataContext}, function(){ | ||
//send all state back to caller | ||
//useful if you need to know what other parts of the app | ||
//were impacted by your changes. You can also use the returned | ||
//information to display things external to your ApplicationModel | ||
//Allows you to have multiple Application ViewModels in the one app and | ||
//still share the state with other presentation models that may be interested | ||
if(typeof callback === 'function'){ | ||
if(this.state !== null && ('appContext' in this.state)){ | ||
callback(this.state.appContext); | ||
} else { | ||
callback(void 0); | ||
} | ||
} | ||
}.bind(this)); | ||
}, | ||
getInitialState: function(){ | ||
var appDataContext = core.getInitialState(NAMESPACE, this.props.viewModel, this.props.initArgs, | ||
this.props.dataContexts, this.stateChangedHandler, this.props.noUndo); | ||
return {appContext: appDataContext}; | ||
} | ||
}; | ||
module.exports = mixin; | ||
},{"./core":2}],9:[function(_dereq_,module,exports){ | ||
'use strict'; | ||
var utils = { | ||
getDescriptor: function(){ | ||
var descriptor = {}; | ||
var proto = this.prototype; | ||
//var originalSpec = this.originalSpec || {}; | ||
for(var key in this.originalSpec){ | ||
if(this.originalSpec.hasOwnProperty(key)){ | ||
if('get' in this.originalSpec[key] || 'set' in this.originalSpec[key]){ | ||
//assume it is a descriptor | ||
if(!('enumerable' in this.originalSpec[key])){ | ||
//default enumerable to true | ||
this.originalSpec[key].enumerable = true; | ||
} | ||
descriptor[key] = this.originalSpec[key]; | ||
} else { | ||
proto[key] = this.originalSpec[key]; | ||
} | ||
} | ||
} | ||
proto.extend = utils.extend; | ||
return { | ||
descriptor: descriptor, | ||
proto: proto, | ||
originalSpec: this.originalSpec || {} | ||
} | ||
}, | ||
extend: function () { | ||
@@ -496,0 +532,0 @@ var newObj = {}; |
@@ -1,1 +0,1 @@ | ||
!function(b){if("object"==typeof exports){module.exports=b()}else{if("function"==typeof define&&define.amd){define(b)}else{var a;"undefined"!=typeof window?a=window:"undefined"!=typeof global?a=global:"undefined"!=typeof self&&(a=self),a.IMVVM=b()}}}(function(){var d,b,a;return(function c(f,k,h){function g(n,l){if(!k[n]){if(!f[n]){var i=typeof require=="function"&&require;if(!l&&i){return i(n,!0)}if(e){return e(n,!0)}throw new Error("Cannot find module '"+n+"'")}var m=k[n]={exports:{}};f[n][0].call(m.exports,function(o){var p=f[n][1][o];return g(p?p:o)},m,m.exports,c,f,k,h)}return k[n].exports}var e=typeof require=="function"&&require;for(var j=0;j<h.length;j++){g(h[j])}return g})({1:[function(h,g,f){var e=h("./src/imvvm.js");g.exports=e},{"./src/imvvm.js":2}],2:[function(i,h,g){var j=i("./imvvmModelBase");var f=i("./imvvmMixin");var e={createModel:j.createModel,createViewModel:j.createViewModel,createAppViewModel:j.createAppViewModel,imvvmMixin:f};h.exports=e},{"./imvvmMixin":4,"./imvvmModelBase":5}],3:[function(h,g,f){var e=h("./utils");var i=e.extend;f.Main=function(m,u,k,l,v,q){if(typeof v!=="function"){throw new TypeError()}var j=m,y=void 0,p={},w,o={};var r=function(B,G,D){var H=false,E,A;G=G||{};if(B===void 0){A=true;B={}}var C=function(J){var L={},K,I;if("dependsOn" in J){J.dependsOn.forEach(function(M){I={};K=M.property.split(".");K.forEach(function(O,N){if(N===0){I=B[O]}else{I=I?I[O]:void 0}});if("alias" in M){L[M.alias]=I}else{L[K.join("_")]=I}})}return L};for(var F in l){if(l.hasOwnProperty(F)){E=C(l[F]);if(A){B[F]=new p[F](B[F],E,G[F]).init(l[F].initArgs)}else{B[F]=new p[F](B[F],E,G[F])}if(D){if(H&&D.subscribers.indexOf(F)!==-1){E=C(l[D.name]);B[D.name]=new p[D.name](B[D.name],E,G[D.name])}H=H?H:F===D.name}}}return B};var n=function(B,C,J,F){var I,M={},H=void 0,L=void 0,G,E,K;if(B in o){G=Object.keys(C);E=G.length;K={};for(var D=0;D<E;D++){if(o[B][G[D]]){K[o[B][G[D]]]=true}}L={};L.name=B;L.subscribers=Object.keys(K);L=!!L.subscribers.length?L:void 0}var A=!!C?Object.getPrototypeOf(C).constructor.classType==="AppViewModel":false;if(A){M=i(C.state);H=C.state.previousState}else{if(B!==j){M[B]=C;M=i(y.state,M)}else{if(F){M=i(r(),C)}else{M=i(y.state,C)}}H=y;M=r(M,y?y.state:void 0,L)}if(H){Object.freeze(H)}y=new z(M,q?void 0:H);I=Object.freeze(y.state);v(I,J);return I};var z=u.call(this,n.bind(this,j));for(var x in l){if(l.hasOwnProperty(x)){p[x]=l[x].viewModel.call(this,n.bind(this,x));if("dependsOn" in l[x]){for(var s=0,t=l[x].dependsOn.length;s<t;s++){w=l[x].dependsOn[s].property.split(".");if(w.length>1){o[w[0]]=o[w[0]]||{};o[w[0]][w[1]]=o[w[0]][w[1]]||[];if(o[w[0]][w[1]].indexOf(x)===-1){o[w[0]][w[1]].push(x)}}}}}}return new z().init(k)}},{"./utils":6}],4:[function(j,i,h){var f=j("./imvvmMain");var e="__IMVVM__";var g={stateChangedHandler:function(k,l){this.setState({appContext:k},function(){if(typeof l==="function"){if(this.state!==null&&("appContext" in this.state)){l(this.state.appContext)}else{l(void 0)}}}.bind(this))},getInitialState:function(){var k=f.Main(e,this.props.viewModel,this.props.initArgs,this.props.dataContexts,this.stateChangedHandler,this.props.noUndo);return{appContext:k}}};i.exports=g},{"./imvvmMain":3}],5:[function(f,g,i){var m=f("./utils");var l=m.extend;var k=m.mixInto;var j=function(){};var h={Mixin:{construct:function(s){var v,o={};var u=this.prototype;var q=this.classType==="Model";var w=this.classType==="ViewModel";var r=this.classType==="AppViewModel";var t=this.originalSpec||{};for(v in this.originalSpec){if(this.originalSpec.hasOwnProperty(v)){if("get" in this.originalSpec[v]||"set" in this.originalSpec[v]){if(!("enumerable" in this.originalSpec[v])){this.originalSpec[v].enumerable=true}o[v]=this.originalSpec[v]}else{u[v]=this.originalSpec[v]}}}if(!q){u.setState=s}u.extend=l;var p=function(C,x,B){if(w){u.DataContext=p;if(!("init" in u)){u.init=function(){return this.DataContext()}}}if(r){u.DataContext=function(F,G,E){return u.setState(F,G,true)};if(!("init" in u)){u.init=function(){return this.DataContext()}}}var A=Object.create(u,o);if(q){var D=arguments.length;var z=typeof Array.prototype.slice.call(arguments,-1)[0]==="boolean";if(D===1){if(z){x=C;C={}}else{x=true}}else{if(D===2){if(!z){B=x;x=true}}else{if(D===3){if(z){var y=x;x=B;B=y}}else{C={};x=true}}}if(t.getInitialState){C=l(C,t.getInitialState(C,B))}if(x){Object.defineProperty(A,"context",{configurable:true,enumerable:true,set:function(E){this.setState=s(E);delete this.context}})}}else{C=C||{};if(w){C=l(C,x);if(t.getInitialState){C=l(C,t.getInitialState(C,B))}Object.defineProperty(A,"state",{configurable:false,enumerable:false,writable:false,value:C});Object.keys(A).map(function(E){if(Object.prototype.toString.call(this[E])==="[object Object]"&&("context" in this[E])){this[E].context=this;Object.freeze(this[E])}}.bind(A));C.__proto__=A.__proto__;return Object.freeze(C)}else{if(!!x){Object.defineProperty(C,"previousState",{configurable:false,enumerable:true,writable:false,value:x})}if(t.getInitialState){C=l(C,t.getInitialState(C,x?x.state:void 0))}C.__proto__=A.__proto__}}Object.defineProperty(A,"state",{configurable:false,enumerable:false,writable:false,value:C});return A}.bind(this);return p}}};k(j,h.Mixin);var e={createClass:function(p,o){var s=function(){};s.prototype=new j();s.prototype.constructor=s;var r=s;var q=function(t){var u=new r();return u.construct.apply(q,arguments)};q.componentConstructor=s;s.ConvenienceConstructor=q;q.originalSpec=o;q.type=s;s.prototype.type=s;q.classType=p;s.prototype.classType=p;return q}};var n={createModel:e.createClass.bind(this,"Model"),createViewModel:e.createClass.bind(this,"ViewModel"),createAppViewModel:e.createClass.bind(this,"AppViewModel")};g.exports=n},{"./utils":6}],6:[function(h,g,f){var e={extend:function(){var j={};for(var l=0;l<arguments.length;l++){var m=arguments[l];for(var k in m){if(m.hasOwnProperty(k)){j[k]=m[k]}}}return j},mixInto:function(j,k){var i;for(i in k){if(!k.hasOwnProperty(i)){continue}j.prototype[i]=k[i]}}};g.exports=e},{}]},{},[1])(1)}); | ||
!function(b){if("object"==typeof exports){module.exports=b()}else{if("function"==typeof define&&define.amd){define(b)}else{var a;"undefined"!=typeof window?a=window:"undefined"!=typeof global?a=global:"undefined"!=typeof self&&(a=self),a.IMVVM=b()}}}(function(){var d,b,a;return(function c(f,k,h){function g(n,l){if(!k[n]){if(!f[n]){var i=typeof require=="function"&&require;if(!l&&i){return i(n,!0)}if(e){return e(n,!0)}throw new Error("Cannot find module '"+n+"'")}var m=k[n]={exports:{}};f[n][0].call(m.exports,function(o){var p=f[n][1][o];return g(p?p:o)},m,m.exports,c,f,k,h)}return k[n].exports}var e=typeof require=="function"&&require;for(var j=0;j<h.length;j++){g(h[j])}return g})({1:[function(h,g,f){var e=h("./src/imvvm.js");g.exports=e},{"./src/imvvm.js":3}],2:[function(h,g,f){var e=h("./utils");var i=e.extend;f.getInitialState=function(m,u,k,l,v,q){if(typeof v!=="function"){throw new TypeError()}var j=m,y=void 0,p={},w,o={};var r=function(B,G,D){var H=false,E,A;G=G||{};if(B===void 0){A=true;B={}}var C=function(J){var L={},K,I;if("dependsOn" in J){J.dependsOn.forEach(function(M){I={};K=M.property.split(".");K.forEach(function(O,N){if(N===0){I=B[O]}else{I=I?I[O]:void 0}});if("alias" in M){L[M.alias]=I}else{L[K.join("_")]=I}})}return L};for(var F in l){if(l.hasOwnProperty(F)){E=C(l[F]);if(A){B[F]=new p[F](B[F],E,G[F]).init(l[F].initArgs)}else{B[F]=new p[F](B[F],E,G[F])}if(D){if(H&&D.subscribers.indexOf(F)!==-1){E=C(l[D.name]);B[D.name]=new p[D.name](B[D.name],E,G[D.name])}H=H?H:F===D.name}}}return B};var n=function(B,C,J,F){var I,M={},H=void 0,L=void 0,G,E,K;if(B in o){G=Object.keys(C);E=G.length;K={};for(var D=0;D<E;D++){if(o[B][G[D]]){K[o[B][G[D]]]=true}}L={};L.name=B;L.subscribers=Object.keys(K);L=!!L.subscribers.length?L:void 0}var A=!!C?Object.getPrototypeOf(C).constructor.classType==="AppViewModel":false;if(A){M=i(C.state);H=C.state.previousState}else{if(B!==j){M[B]=C;M=i(y.state,M)}else{if(F){M=i(r(),C)}else{M=i(y.state,C)}}H=y;M=r(M,y?y.state:void 0,L)}if(H){Object.freeze(H)}y=new z(M,q?void 0:H);I=Object.freeze(y.state);v(I,J);return I};var z=u.call(this,n.bind(this,j));for(var x in l){if(l.hasOwnProperty(x)){p[x]=l[x].viewModel.call(this,n.bind(this,x));if("dependsOn" in l[x]){for(var s=0,t=l[x].dependsOn.length;s<t;s++){w=l[x].dependsOn[s].property.split(".");if(w.length>1){o[w[0]]=o[w[0]]||{};o[w[0]][w[1]]=o[w[0]][w[1]]||[];if(o[w[0]][w[1]].indexOf(x)===-1){o[w[0]][w[1]].push(x)}}}}}}return new z().init(k)}},{"./utils":9}],3:[function(i,h,g){var j=i("./imvvmBase");var f=i("./mixin");var e={createModel:j.createModel,createViewModel:j.createViewModel,createAppViewModel:j.createAppViewModel,mixin:f};h.exports=e},{"./imvvmBase":5,"./mixin":8}],4:[function(j,i,g){var e=j("./utils");var k=e.extend;var h=e.getDescriptor;var f={Mixin:{construct:function(m){var n=h.call(this);n.proto.setState=m;var l=function(r,o,q){r=r||{};if(!!o){Object.defineProperty(r,"previousState",{configurable:false,enumerable:true,writable:false,value:o})}if(n.originalSpec.getInitialState){r=k(r,n.originalSpec.getInitialState(r,o?o.state:void 0))}n.proto.DataContext=function(t,u,s){return n.proto.setState(t,u,true)};if(!("init" in n.proto)){n.proto.init=function(){return this.DataContext()}}var p=Object.create(n.proto,n.descriptor);r.__proto__=p.__proto__;Object.defineProperty(p,"state",{configurable:false,enumerable:false,writable:false,value:r});return p};return l}}};i.exports=f},{"./utils":9}],5:[function(f,g,j){var r=f("./utils");var p=r.extend;var n=r.mixInto;var k=f("./imvvmModel");var q=f("./imvvmViewModel");var m=f("./imvvmAppViewModel");var l=function(){};var i=function(){};var h=function(){};n(l,k.Mixin);n(i,q.Mixin);n(h,m.Mixin);var e={createClass:function(t,u,s){var x=function(){};x.prototype=new t();x.prototype.constructor=x;var w=x;var v=function(y){var z=new w();return z.construct.apply(v,arguments)};v.componentConstructor=x;x.ConvenienceConstructor=v;v.originalSpec=s;v.type=x;x.prototype.type=x;v.classType=u;x.prototype.classType=u;return v}};var o={createModel:e.createClass.bind(this,l,"Model"),createViewModel:e.createClass.bind(this,i,"ViewModel"),createAppViewModel:e.createClass.bind(this,h,"AppViewModel")};g.exports=o},{"./imvvmAppViewModel":4,"./imvvmModel":6,"./imvvmViewModel":7,"./utils":9}],6:[function(i,h,f){var e=i("./utils");var k=e.extend;var g=e.getDescriptor;var j={Mixin:{construct:function(m){var n=g.call(this);var l=function(t,o,s){var r=Object.create(n.proto,n.descriptor);var u=arguments.length;var q=typeof Array.prototype.slice.call(arguments,-1)[0]==="boolean";if(u===1){if(q){o=t;t={}}else{o=true}}else{if(u===2){if(!q){s=o;o=true}}else{if(u===3){if(q){var p=o;o=s;s=p}}else{t={};o=true}}}if(n.originalSpec.getInitialState){t=k(t,n.originalSpec.getInitialState(t,s))}if(o){Object.defineProperty(r,"context",{configurable:true,enumerable:true,set:function(v){this.setState=m(v);delete this.context}})}Object.defineProperty(r,"state",{configurable:false,enumerable:false,writable:false,value:t});return r};return l}}};h.exports=j},{"./utils":9}],7:[function(j,i,g){var f=j("./utils");var k=f.extend;var h=f.getDescriptor;var e={Mixin:{construct:function(m){var n=h.call(this);n.proto.setState=m;var l=function(r,q,p){r=r||{};r=k(r,q);if(n.originalSpec.getInitialState){r=k(r,n.originalSpec.getInitialState(r,p))}n.proto.DataContext=l;if(!("init" in n.proto)){n.proto.init=function(){return this.DataContext()}}var o=Object.create(n.proto,n.descriptor);Object.defineProperty(o,"state",{configurable:false,enumerable:false,writable:false,value:r});Object.keys(o).map(function(s){if(Object.prototype.toString.call(this[s])==="[object Object]"&&("context" in this[s])){this[s].context=this;Object.freeze(this[s])}}.bind(o));r.__proto__=o.__proto__;return Object.freeze(r)};return l}}};i.exports=e},{"./utils":9}],8:[function(j,i,h){var f=j("./core");var e="__IMVVM__";var g={stateChangedHandler:function(k,l){this.setState({appContext:k},function(){if(typeof l==="function"){if(this.state!==null&&("appContext" in this.state)){l(this.state.appContext)}else{l(void 0)}}}.bind(this))},getInitialState:function(){var k=f.getInitialState(e,this.props.viewModel,this.props.initArgs,this.props.dataContexts,this.stateChangedHandler,this.props.noUndo);return{appContext:k}}};i.exports=g},{"./core":2}],9:[function(h,g,f){var e={getDescriptor:function(){var k={};var j=this.prototype;for(var i in this.originalSpec){if(this.originalSpec.hasOwnProperty(i)){if("get" in this.originalSpec[i]||"set" in this.originalSpec[i]){if(!("enumerable" in this.originalSpec[i])){this.originalSpec[i].enumerable=true}k[i]=this.originalSpec[i]}else{j[i]=this.originalSpec[i]}}}j.extend=e.extend;return{descriptor:k,proto:j,originalSpec:this.originalSpec||{}}},extend:function(){var j={};for(var l=0;l<arguments.length;l++){var m=arguments[l];for(var k in m){if(m.hasOwnProperty(k)){j[k]=m[k]}}}return j},mixInto:function(j,k){var i;for(i in k){if(!k.hasOwnProperty(i)){continue}j.prototype[i]=k[i]}}};g.exports=e},{}]},{},[1])(1)}); |
@@ -12,3 +12,3 @@ /** | ||
var ApplicationView = React.createClass({ | ||
mixins: [IMVVM.imvvmMixin], | ||
mixins: [IMVVM.mixin], | ||
@@ -15,0 +15,0 @@ render: function(){ |
{ | ||
"name": "imvvm", | ||
"private": true, | ||
"dependencies": { | ||
@@ -5,0 +4,0 @@ "jquery": "~1.10.2", |
{ | ||
"name": "imvvm", | ||
"description": "Immutable MVVM for React", | ||
"version": "0.1.3-alpha", | ||
"version": "0.1.4-alpha", | ||
"keywords": [ | ||
@@ -24,5 +24,7 @@ "imvvm", | ||
}, | ||
"main": "./main.js", | ||
"main": "main.js", | ||
"devDependencies": { | ||
"browserify": "^3.33.0", | ||
"yuicompressor": "^2.4.8" | ||
} | ||
} |
'use strict' | ||
var base = require('./imvvmModelBase'); | ||
var mixin = require('./imvvmMixin'); | ||
var base = require('./imvvmBase'); | ||
var mixin = require('./mixin'); | ||
@@ -10,5 +10,5 @@ var IMVVM = { | ||
createAppViewModel: base.createAppViewModel, | ||
imvvmMixin: mixin | ||
mixin: mixin | ||
}; | ||
module.exports = IMVVM; |
'use strict'; | ||
var utils = { | ||
getDescriptor: function(){ | ||
var descriptor = {}; | ||
var proto = this.prototype; | ||
//var originalSpec = this.originalSpec || {}; | ||
for(var key in this.originalSpec){ | ||
if(this.originalSpec.hasOwnProperty(key)){ | ||
if('get' in this.originalSpec[key] || 'set' in this.originalSpec[key]){ | ||
//assume it is a descriptor | ||
if(!('enumerable' in this.originalSpec[key])){ | ||
//default enumerable to true | ||
this.originalSpec[key].enumerable = true; | ||
} | ||
descriptor[key] = this.originalSpec[key]; | ||
} else { | ||
proto[key] = this.originalSpec[key]; | ||
} | ||
} | ||
} | ||
proto.extend = utils.extend; | ||
return { | ||
descriptor: descriptor, | ||
proto: proto, | ||
originalSpec: this.originalSpec || {} | ||
} | ||
}, | ||
extend: function () { | ||
@@ -5,0 +30,0 @@ var newObj = {}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
120443
50
2060
2
5