Comparing version 0.6.20 to 0.7.0
{ | ||
"name": "imvvm", | ||
"version": "0.6.20", | ||
"version": "0.7.0", | ||
"homepage": "https://github.com/entrendipity/imvvm", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -21,2 +21,8 @@ ## 0.6.17 | ||
## 0.7.0 | ||
- stateChangedHandler now only provides `nextState` argument. `prevState` has been removed | ||
- `this.extend` removed. Use IMVVM.extend. | ||
- Enabled multiple models within one ViewModel. | ||
@@ -278,3 +278,2 @@ !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){ | ||
} | ||
} | ||
@@ -322,4 +321,2 @@ for(watchedProp in watchedState[watchedItem].fields){ | ||
Object.freeze(appState); | ||
console.warn('\"this.extend\" has been deprecated and will not be available in 0.7. Please use \"IMVVM.extend\".'); | ||
return appState; | ||
@@ -424,6 +421,2 @@ }; | ||
} | ||
/* deprecated - to be removed */ | ||
if(!('extend' in proto)){ | ||
proto.extend = utils.extend; | ||
} | ||
@@ -470,3 +463,3 @@ if(!!Object.keys(viewModels).length){ | ||
var desc = this.getDescriptor(this); | ||
var desc = this.getDescriptor(); | ||
desc.proto.setState = stateChangedHandler; | ||
@@ -587,7 +580,5 @@ | ||
var desc = this.getDescriptor(this); | ||
desc.stateChangedHandler = stateChangedHandler; | ||
var desc = this.getDescriptor(); | ||
var dataContext = function(nextState, extendState, initialize) { | ||
var freezeFields = desc.freezeFields, | ||
@@ -646,2 +637,6 @@ fld, | ||
model.__stateChangedHandler = (function(){ | ||
return stateChangedHandler; | ||
})(); | ||
return Object.freeze(model); | ||
@@ -707,2 +702,6 @@ }; | ||
tempModel.__stateChangedHandler = (function(fld){ | ||
return viewModel[fld].__stateChangedHandler; | ||
})(freezeFields[fld].fieldName); | ||
Object.defineProperty(tempModel, 'state', { | ||
@@ -715,6 +714,5 @@ configurable: true, | ||
tempModel.__proto__.setState = function(someState, callback){ //callback may be useful for DB updates | ||
return tempDesc.stateChangedHandler.call(this, | ||
extend(tempModel.state, someState), tempModel.state, callback); | ||
}.bind(viewModel); | ||
tempModel.__proto__.setState = function(state, callback){ //callback may be useful for DB updates | ||
this.__stateChangedHandler.call(viewModel, extend(this.state, state), callback); | ||
}; | ||
@@ -721,0 +719,0 @@ Object.freeze(viewModel[freezeFields[fld].fieldName]); |
@@ -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":3}],2:[function(h,g,f){var e=h("./utils");var i=e.extend;f.getInitialState=function(l,m,v,k){if(typeof v!=="function"){throw new TypeError("stateChangedHandler must be a function!")}k===void (0)?true:k;var A,u={},r={},B,j={},y={},t,q={},o={},x,w,z,s,p;var n=function(E,J,L,Q){var S={},O=void (0),G=void (0),M,H,F,D,I,K=[],P,N,C,R;if(typeof L==="function"){Q=L;L={}}J=J||{};M=Object.keys(J);if(Object.getPrototypeOf(J).constructor.classType==="DomainViewModel"){S=i(J);O=J.previousState;G=L;for(D in B){S[D]=new r[D](S[D])}for(D in B){if(B.hasOwnProperty(D)){for(I in j[D]){if(j[D].hasOwnProperty(I)){S[D].state[j[D][I]]=(I in B)?i(S[I].state):S[I]}}}}if(typeof Q==="function"){u=new A(S,O,G,k);Q();return}}else{if(!!M.length){if(E===l){S=i(J)}else{S[E]=i(J)}}q=i(S,q,L);transientStateKeys=Object.keys(q);if(transientStateKeys.length===0){return}if(typeof Q==="function"){Q();return}F=transientStateKeys.length-1;for(H=F;H>=0;H--){if(transientStateKeys[H] in B){S[transientStateKeys[H]]=i(u[transientStateKeys[H]],q[transientStateKeys[H]]);S[transientStateKeys[H]]=new r[transientStateKeys[H]](S[transientStateKeys[H]])}else{S[transientStateKeys[H]]=q[transientStateKeys[H]]}}o=i(o,S);S=i(u,o);q={};for(H=F;H>=0;H--){if(transientStateKeys[H] in y){for(N in y[transientStateKeys[H]]){if(y[transientStateKeys[H]].hasOwnProperty(N)){if(M.indexOf(N)!==-1){C=y[transientStateKeys[H]][N];for(R in C){if(C.hasOwnProperty(R)){if(R in j){for(D in j[R]){if(j[R].hasOwnProperty(D)){S[R].state[j[R][D]]=(D in B)?i(S[D].state):S[D]}if(D in j){for(dataContext2 in j[D]){if(j[D].hasOwnProperty(dataContext2)){S[D].state[j[D][dataContext2]]=(dataContext2 in B)?i(S[dataContext2].state):S[dataContext2]}}}}}q=i(q,C[R].call(u[R],S[transientStateKeys[H]][N],u[transientStateKeys[H]][N],N,transientStateKeys[H]))}}}}}}}if(!!Object.keys(q).length){n(void (0),{},q);return}K=Object.keys(o);P=K.length-1;for(H=P;H>=0;H--){if(E===l){if(K[H] in j[l]){for(D in j[l][K[H]]){if(j[l][K[H]].hasOwnProperty(D)){S[D].state[j[l][K[H]][D]]=S[K[H]]}if(D in j){for(dataContext2 in j[D]){if(j[D].hasOwnProperty(dataContext2)){S[D].state[j[D][dataContext2]]=(dataContext2 in B)?i(S[dataContext2].state):S[dataContext2]}}}}}}else{if(K[H] in j){for(D in j[K[H]]){if(j[K[H]].hasOwnProperty(D)){S[K[H]].state[j[K[H]][D]]=(D in B)?i(S[D].state):S[D]}if(D in j){for(dataContext2 in j[D]){if(j[D].hasOwnProperty(dataContext2)){S[D].state[j[D][dataContext2]]=(dataContext2 in B)?i(S[dataContext2].state):S[dataContext2]}}}}}}}O=u}if(!!O){Object.freeze(O)}u=new A(S,O,G,k);Object.freeze(u);Object.freeze(u.state);v(u);q={};o={}};A=m.call(this,n.bind(this,l));u=new A(void (0),void (0),void (0),k);u.state=u.state||{};B=u.constructor.originalSpec.getDomainDataContext();delete u.constructor.originalSpec.getDomainDataContext;for(t in B){if(B.hasOwnProperty(t)){r[t]=B[t].call(this,n.bind(this,t));u.state[t]=new r[t](u.state[t],true)}}for(t in B){if(B.hasOwnProperty(t)){if("getWatchedState" in u[t].constructor.originalSpec){x=u[t].constructor.originalSpec.getWatchedState();for(w in x){if(x.hasOwnProperty(w)){if(w in B||w in u.state){if("alias" in x[w]){if(!(t in j)){j[t]={}}j[t][w]=x[w].alias;if(!(w in B)){if(!(l in j)){j[l]={}}if(!(t in j[l])){j[l][w]={}}j[l][w][t]=x[w].alias}}for(z in x[w].fields){if(x[w].fields.hasOwnProperty(z)){if(w in B){s={};if(!(w in y)){y[w]={}}s[z]={};s[z][t]=x[w].fields[z];y[w]=s}}}}}}}}}for(t in B){if(B.hasOwnProperty(t)){for(p in j[t]){if(j[t].hasOwnProperty(p)){u[t].state[j[t][p]]=(p in B)?i(u[p].state):u[p]}}}}for(t in B){if(B.hasOwnProperty(t)){u.state[t]=new r[t](u.state[t],true)}}u=new A(u,void (0),void (0),k);Object.freeze(u.state);Object.freeze(u);console.warn('"this.extend" has been deprecated and will not be available in 0.7. Please use "IMVVM.extend".');return u}},{"./utils":8}],3:[function(f,g,j){var k=f("./imvvmModel");var p=f("./imvvmViewModel");var i=f("./imvvmDomainViewModel");var r=f("./mixin");var q=f("./utils");var o=q.extend;var m=q.mixInto;var l=function(){};var h=function(){};var n=function(){};m(l,k.Mixin);m(h,p.Mixin);m(n,i.Mixin);var e={createClass:function(u,v,t){var y=function(){};y.prototype=new u();y.prototype.constructor=y;var x=y;var w=function(z){var A=new x();return A.construct.apply(w,arguments)};w.componentConstructor=y;y.ConvenienceConstructor=w;w.originalSpec=t;w.type=y;y.prototype.type=y;w.classType=v;y.prototype.classType=v;w.getDescriptor=function(){var E={},D=this.prototype,B={},z=[],A={},C;if("__processedSpec__" in this.originalSpec){return this.originalSpec.__processedSpec__}for(C in this.originalSpec){if(this.originalSpec.hasOwnProperty(C)){if("get" in this.originalSpec[C]||"set" in this.originalSpec[C]){this.originalSpec[C].enumerable=true;if("viewModel" in this.originalSpec[C]){B[C]=this.originalSpec[C].viewModel;delete this.originalSpec[C].viewModel;delete this.originalSpec[C].set}else{if("aliasFor" in this.originalSpec[C]){A[this.originalSpec[C].aliasFor]=C;delete this.originalSpec[C].aliasFor}if("kind" in this.originalSpec[C]){if(this.originalSpec[C].kind==="pseudo"){this.originalSpec[C].enumerable=false}else{if(this.originalSpec[C].kind==="instance"||this.originalSpec[C].kind==="array"){z.push({fieldName:C,kind:this.originalSpec[C].kind})}else{throw new TypeError('"'+this.originalSpec[C].kind+'" is not a valid "kind" value. Valid values are "pseudo","instance" and "array". Please review field "'+C+'".')}}delete this.originalSpec[C].kind}}E[C]=this.originalSpec[C]}else{if(C!=="getInitialState"&&C!=="getWatchedState"){D[C]=this.originalSpec[C]}}}}if(!("extend" in D)){D.extend=q.extend}if(!!Object.keys(B).length){this.originalSpec.getDomainDataContext=function(){return B}}this.originalSpec.__processedSpec__={descriptor:E,proto:D,originalSpec:this.originalSpec||{},freezeFields:z,aliases:A};return this.originalSpec.__processedSpec__};return w}};var s={createModel:e.createClass.bind(this,l,"Model"),createViewModel:e.createClass.bind(this,h,"ViewModel"),createDomainViewModel:e.createClass.bind(this,n,"DomainViewModel"),mixin:r,extend:o};g.exports=s},{"./imvvmDomainViewModel":4,"./imvvmModel":5,"./imvvmViewModel":6,"./mixin":7,"./utils":8}],4:[function(i,h,g){var f=i("./utils");var j=f.extend;var e={Mixin:{construct:function(l){var m=this.getDescriptor(this);m.proto.setState=l;m.proto.undo=function(){this.setState(this.previousState,!!this.previousState?this:void (0))};m.proto.redo=function(){if(this.canRedo){this.setState(this.nextState,this.nextState.nextState)}};var k=function(p,t,o,s){var r=m.freezeFields,q=Object.create(m.proto,m.descriptor),n;if(!!s){if(!!t){Object.defineProperty(q,"previousState",{configurable:false,enumerable:false,writable:false,value:t});Object.defineProperty(q,"canUndo",{configurable:false,enumerable:false,writable:false,value:true})}else{Object.defineProperty(q,"canUndo",{configurable:false,enumerable:false,writable:false,value:false})}if(!!o&&"state" in o){Object.defineProperty(q,"nextState",{configurable:false,enumerable:false,writable:false,value:o});Object.defineProperty(q,"canRedo",{configurable:false,enumerable:false,writable:false,value:true})}else{Object.defineProperty(q,"canRedo",{configurable:false,enumerable:false,writable:false,value:false})}}if(p===void (0)){p=("getInitialState" in m.originalSpec)?m.originalSpec.getInitialState.call(q):{}}else{if("state" in p){delete p.state;Object.defineProperty(q,"state",{configurable:true,enumerable:false,writable:true,value:p});p=j(p,q)}}for(n=r.length-1;n>=0;n--){if(r[n].kind==="array"){p[r[n].fieldName]=p[r[n].fieldName]||[];Object.freeze(p[r[n].fieldName])}else{throw new TypeError('kind:"instance" can only be specified in a ViewModel.')}}Object.defineProperty(q,"state",{configurable:false,enumerable:false,writable:false,value:p});return q};return k}}};h.exports=e},{"./utils":8}],5:[function(h,g,f){var e=h("./utils");var j=e.extend;var i={Mixin:{construct:function(l){var m=this.getDescriptor(this);m.stateChangedHandler=l;var k=function(r,p,n){var s=m.freezeFields,q,o=Object.create(m.proto,m.descriptor);if(r===void (0)){n=true}else{if(typeof r==="boolean"){n=r;r=void (0)}else{if(typeof p==="boolean"){n=p;p=void (0)}}}r=j(r,p);Object.defineProperty(o,"state",{configurable:true,enumerable:false,writable:true,value:r});r=j(r,o);if(n){for(var t in m.aliases){if(m.aliases.hasOwnProperty(t)&&t in r){r[m.aliases[t]]=r[t];delete r[t]}}if("getInitialState" in m.originalSpec){r=j(r,m.originalSpec.getInitialState.call(o))}}for(q=s.length-1;q>=0;q--){if(s[q].kind==="array"){r[s[q].fieldName]=r[s[q].fieldName]||[];Object.freeze(r[s[q].fieldName])}else{throw new TypeError('kind:"instance" can only be specified in a ViewModel.')}}Object.defineProperty(o,"state",{configurable:false,enumerable:false,writable:false,value:r});return Object.freeze(o)};return k}}};g.exports=i},{"./utils":8}],6:[function(i,h,g){var f=i("./utils");var j=f.extend;var e={Mixin:{construct:function(l){var m=this.getDescriptor(this);m.proto.setState=l;var k=function(r,n){r=r||{};r=("state" in r?r.state:r);var s=m.freezeFields,q,p=Object.create(m.proto,m.descriptor),t,o;Object.defineProperty(p,"state",{configurable:true,enumerable:false,writable:true,value:r});if(n){r=("getInitialState" in m.originalSpec)?j(r,m.originalSpec.getInitialState.call(p)):r;Object.defineProperty(p,"state",{configurable:true,enumerable:false,writable:true,value:r})}for(q=s.length-1;q>=0;q--){if(s[q].kind==="instance"){if(p[s[q].fieldName]){t=p[s[q].fieldName].constructor.originalSpec.__processedSpec__;o=Object.create(t.proto,t.descriptor);Object.defineProperty(o,"state",{configurable:true,enumerable:false,writable:true,value:p[s[q].fieldName].state});o.__proto__.setState=function(u,v){return t.stateChangedHandler.call(this,j(o.state,u),o.state,v)}.bind(p);Object.freeze(p[s[q].fieldName])}}else{r[s[q].fieldName]=r[s[q].fieldName]||[];Object.freeze(r[s[q].fieldName])}}Object.defineProperty(p,"state",{configurable:false,enumerable:false,writable:false,value:r});return Object.freeze(p)};return k}}};h.exports=e},{"./utils":8}],7:[function(j,i,h){var f=j("./core");var e="__IMVVM__";var g={stateChangedHandler:function(k){this.setState({domainDataContext:k})},getInitialState:function(){var k=f.getInitialState(e,this.props.domainModel,this.stateChangedHandler,this.props.enableUndo);return{domainDataContext:k}}};i.exports=g},{"./core":2}],8:[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(l,m,v,k){if(typeof v!=="function"){throw new TypeError("stateChangedHandler must be a function!")}k===void (0)?true:k;var A,u={},r={},B,j={},y={},t,q={},o={},x,w,z,s,p;var n=function(E,J,L,Q){var S={},O=void (0),G=void (0),M,H,F,D,I,K=[],P,N,C,R;if(typeof L==="function"){Q=L;L={}}J=J||{};M=Object.keys(J);if(Object.getPrototypeOf(J).constructor.classType==="DomainViewModel"){S=i(J);O=J.previousState;G=L;for(D in B){S[D]=new r[D](S[D])}for(D in B){if(B.hasOwnProperty(D)){for(I in j[D]){if(j[D].hasOwnProperty(I)){S[D].state[j[D][I]]=(I in B)?i(S[I].state):S[I]}}}}if(typeof Q==="function"){u=new A(S,O,G,k);Q();return}}else{if(!!M.length){if(E===l){S=i(J)}else{S[E]=i(J)}}q=i(S,q,L);transientStateKeys=Object.keys(q);if(transientStateKeys.length===0){return}if(typeof Q==="function"){Q();return}F=transientStateKeys.length-1;for(H=F;H>=0;H--){if(transientStateKeys[H] in B){S[transientStateKeys[H]]=i(u[transientStateKeys[H]],q[transientStateKeys[H]]);S[transientStateKeys[H]]=new r[transientStateKeys[H]](S[transientStateKeys[H]])}else{S[transientStateKeys[H]]=q[transientStateKeys[H]]}}o=i(o,S);S=i(u,o);q={};for(H=F;H>=0;H--){if(transientStateKeys[H] in y){for(N in y[transientStateKeys[H]]){if(y[transientStateKeys[H]].hasOwnProperty(N)){if(M.indexOf(N)!==-1){C=y[transientStateKeys[H]][N];for(R in C){if(C.hasOwnProperty(R)){if(R in j){for(D in j[R]){if(j[R].hasOwnProperty(D)){S[R].state[j[R][D]]=(D in B)?i(S[D].state):S[D]}if(D in j){for(dataContext2 in j[D]){if(j[D].hasOwnProperty(dataContext2)){S[D].state[j[D][dataContext2]]=(dataContext2 in B)?i(S[dataContext2].state):S[dataContext2]}}}}}q=i(q,C[R].call(u[R],S[transientStateKeys[H]][N],u[transientStateKeys[H]][N],N,transientStateKeys[H]))}}}}}}}if(!!Object.keys(q).length){n(void (0),{},q);return}K=Object.keys(o);P=K.length-1;for(H=P;H>=0;H--){if(E===l){if(K[H] in j[l]){for(D in j[l][K[H]]){if(j[l][K[H]].hasOwnProperty(D)){S[D].state[j[l][K[H]][D]]=S[K[H]]}if(D in j){for(dataContext2 in j[D]){if(j[D].hasOwnProperty(dataContext2)){S[D].state[j[D][dataContext2]]=(dataContext2 in B)?i(S[dataContext2].state):S[dataContext2]}}}}}}else{if(K[H] in j){for(D in j[K[H]]){if(j[K[H]].hasOwnProperty(D)){S[K[H]].state[j[K[H]][D]]=(D in B)?i(S[D].state):S[D]}if(D in j){for(dataContext2 in j[D]){if(j[D].hasOwnProperty(dataContext2)){S[D].state[j[D][dataContext2]]=(dataContext2 in B)?i(S[dataContext2].state):S[dataContext2]}}}}}}}O=u}if(!!O){Object.freeze(O)}u=new A(S,O,G,k);Object.freeze(u);Object.freeze(u.state);v(u);q={};o={}};A=m.call(this,n.bind(this,l));u=new A(void (0),void (0),void (0),k);u.state=u.state||{};B=u.constructor.originalSpec.getDomainDataContext();delete u.constructor.originalSpec.getDomainDataContext;for(t in B){if(B.hasOwnProperty(t)){r[t]=B[t].call(this,n.bind(this,t));u.state[t]=new r[t](u.state[t],true)}}for(t in B){if(B.hasOwnProperty(t)){if("getWatchedState" in u[t].constructor.originalSpec){x=u[t].constructor.originalSpec.getWatchedState();for(w in x){if(x.hasOwnProperty(w)){if(w in B||w in u.state){if("alias" in x[w]){if(!(t in j)){j[t]={}}j[t][w]=x[w].alias;if(!(w in B)){if(!(l in j)){j[l]={}}if(!(t in j[l])){j[l][w]={}}j[l][w][t]=x[w].alias}}for(z in x[w].fields){if(x[w].fields.hasOwnProperty(z)){if(w in B){s={};if(!(w in y)){y[w]={}}s[z]={};s[z][t]=x[w].fields[z];y[w]=s}}}}}}}}}for(t in B){if(B.hasOwnProperty(t)){for(p in j[t]){if(j[t].hasOwnProperty(p)){u[t].state[j[t][p]]=(p in B)?i(u[p].state):u[p]}}}}for(t in B){if(B.hasOwnProperty(t)){u.state[t]=new r[t](u.state[t],true)}}u=new A(u,void (0),void (0),k);Object.freeze(u.state);Object.freeze(u);return u}},{"./utils":8}],3:[function(f,g,j){var k=f("./imvvmModel");var p=f("./imvvmViewModel");var i=f("./imvvmDomainViewModel");var r=f("./mixin");var q=f("./utils");var o=q.extend;var m=q.mixInto;var l=function(){};var h=function(){};var n=function(){};m(l,k.Mixin);m(h,p.Mixin);m(n,i.Mixin);var e={createClass:function(u,v,t){var y=function(){};y.prototype=new u();y.prototype.constructor=y;var x=y;var w=function(z){var A=new x();return A.construct.apply(w,arguments)};w.componentConstructor=y;y.ConvenienceConstructor=w;w.originalSpec=t;w.type=y;y.prototype.type=y;w.classType=v;y.prototype.classType=v;w.getDescriptor=function(){var E={},D=this.prototype,B={},z=[],A={},C;if("__processedSpec__" in this.originalSpec){return this.originalSpec.__processedSpec__}for(C in this.originalSpec){if(this.originalSpec.hasOwnProperty(C)){if("get" in this.originalSpec[C]||"set" in this.originalSpec[C]){this.originalSpec[C].enumerable=true;if("viewModel" in this.originalSpec[C]){B[C]=this.originalSpec[C].viewModel;delete this.originalSpec[C].viewModel;delete this.originalSpec[C].set}else{if("aliasFor" in this.originalSpec[C]){A[this.originalSpec[C].aliasFor]=C;delete this.originalSpec[C].aliasFor}if("kind" in this.originalSpec[C]){if(this.originalSpec[C].kind==="pseudo"){this.originalSpec[C].enumerable=false}else{if(this.originalSpec[C].kind==="instance"||this.originalSpec[C].kind==="array"){z.push({fieldName:C,kind:this.originalSpec[C].kind})}else{throw new TypeError('"'+this.originalSpec[C].kind+'" is not a valid "kind" value. Valid values are "pseudo","instance" and "array". Please review field "'+C+'".')}}delete this.originalSpec[C].kind}}E[C]=this.originalSpec[C]}else{if(C!=="getInitialState"&&C!=="getWatchedState"){D[C]=this.originalSpec[C]}}}}if(!!Object.keys(B).length){this.originalSpec.getDomainDataContext=function(){return B}}this.originalSpec.__processedSpec__={descriptor:E,proto:D,originalSpec:this.originalSpec||{},freezeFields:z,aliases:A};return this.originalSpec.__processedSpec__};return w}};var s={createModel:e.createClass.bind(this,l,"Model"),createViewModel:e.createClass.bind(this,h,"ViewModel"),createDomainViewModel:e.createClass.bind(this,n,"DomainViewModel"),mixin:r,extend:o};g.exports=s},{"./imvvmDomainViewModel":4,"./imvvmModel":5,"./imvvmViewModel":6,"./mixin":7,"./utils":8}],4:[function(i,h,g){var f=i("./utils");var j=f.extend;var e={Mixin:{construct:function(l){var m=this.getDescriptor();m.proto.setState=l;m.proto.undo=function(){this.setState(this.previousState,!!this.previousState?this:void (0))};m.proto.redo=function(){if(this.canRedo){this.setState(this.nextState,this.nextState.nextState)}};var k=function(p,t,o,s){var r=m.freezeFields,q=Object.create(m.proto,m.descriptor),n;if(!!s){if(!!t){Object.defineProperty(q,"previousState",{configurable:false,enumerable:false,writable:false,value:t});Object.defineProperty(q,"canUndo",{configurable:false,enumerable:false,writable:false,value:true})}else{Object.defineProperty(q,"canUndo",{configurable:false,enumerable:false,writable:false,value:false})}if(!!o&&"state" in o){Object.defineProperty(q,"nextState",{configurable:false,enumerable:false,writable:false,value:o});Object.defineProperty(q,"canRedo",{configurable:false,enumerable:false,writable:false,value:true})}else{Object.defineProperty(q,"canRedo",{configurable:false,enumerable:false,writable:false,value:false})}}if(p===void (0)){p=("getInitialState" in m.originalSpec)?m.originalSpec.getInitialState.call(q):{}}else{if("state" in p){delete p.state;Object.defineProperty(q,"state",{configurable:true,enumerable:false,writable:true,value:p});p=j(p,q)}}for(n=r.length-1;n>=0;n--){if(r[n].kind==="array"){p[r[n].fieldName]=p[r[n].fieldName]||[];Object.freeze(p[r[n].fieldName])}else{throw new TypeError('kind:"instance" can only be specified in a ViewModel.')}}Object.defineProperty(q,"state",{configurable:false,enumerable:false,writable:false,value:p});return q};return k}}};h.exports=e},{"./utils":8}],5:[function(h,g,f){var e=h("./utils");var j=e.extend;var i={Mixin:{construct:function(l){var m=this.getDescriptor();var k=function(r,p,n){var s=m.freezeFields,q,o=Object.create(m.proto,m.descriptor);if(r===void (0)){n=true}else{if(typeof r==="boolean"){n=r;r=void (0)}else{if(typeof p==="boolean"){n=p;p=void (0)}}}r=j(r,p);Object.defineProperty(o,"state",{configurable:true,enumerable:false,writable:true,value:r});r=j(r,o);if(n){for(var t in m.aliases){if(m.aliases.hasOwnProperty(t)&&t in r){r[m.aliases[t]]=r[t];delete r[t]}}if("getInitialState" in m.originalSpec){r=j(r,m.originalSpec.getInitialState.call(o))}}for(q=s.length-1;q>=0;q--){if(s[q].kind==="array"){r[s[q].fieldName]=r[s[q].fieldName]||[];Object.freeze(r[s[q].fieldName])}else{throw new TypeError('kind:"instance" can only be specified in a ViewModel.')}}Object.defineProperty(o,"state",{configurable:false,enumerable:false,writable:false,value:r});o.__stateChangedHandler=(function(){return l})();return Object.freeze(o)};return k}}};g.exports=i},{"./utils":8}],6:[function(i,h,g){var f=i("./utils");var j=f.extend;var e={Mixin:{construct:function(l){var m=this.getDescriptor(this);m.proto.setState=l;var k=function(r,n){r=r||{};r=("state" in r?r.state:r);var s=m.freezeFields,q,p=Object.create(m.proto,m.descriptor),t,o;Object.defineProperty(p,"state",{configurable:true,enumerable:false,writable:true,value:r});if(n){r=("getInitialState" in m.originalSpec)?j(r,m.originalSpec.getInitialState.call(p)):r;Object.defineProperty(p,"state",{configurable:true,enumerable:false,writable:true,value:r})}for(q=s.length-1;q>=0;q--){if(s[q].kind==="instance"){if(p[s[q].fieldName]){t=p[s[q].fieldName].constructor.originalSpec.__processedSpec__;o=Object.create(t.proto,t.descriptor);o.__stateChangedHandler=(function(u){return p[u].__stateChangedHandler})(s[q].fieldName);Object.defineProperty(o,"state",{configurable:true,enumerable:false,writable:true,value:p[s[q].fieldName].state});o.__proto__.setState=function(u,v){this.__stateChangedHandler.call(p,j(this.state,u),v)};Object.freeze(p[s[q].fieldName])}}else{r[s[q].fieldName]=r[s[q].fieldName]||[];Object.freeze(r[s[q].fieldName])}}Object.defineProperty(p,"state",{configurable:false,enumerable:false,writable:false,value:r});return Object.freeze(p)};return k}}};h.exports=e},{"./utils":8}],7:[function(j,i,h){var f=j("./core");var e="__IMVVM__";var g={stateChangedHandler:function(k){this.setState({domainDataContext:k})},getInitialState:function(){var k=f.getInitialState(e,this.props.domainModel,this.stateChangedHandler,this.props.enableUndo);return{domainDataContext:k}}};i.exports=g},{"./core":2}],8:[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)}); |
@@ -168,3 +168,3 @@ /*jshint unused: false */ | ||
return personModel; | ||
}()); | ||
})(); | ||
@@ -24,3 +24,3 @@ /*jshint unused: false */ | ||
var hobbyStateChangedHandler = function(nextState, prevState/*, callback*/){ | ||
var hobbyStateChangedHandler = function(nextState/*, callback*/){ | ||
@@ -100,3 +100,3 @@ var newState = {}; | ||
//OR use a callback | ||
this.setState({current: Hobby(this.hobbies[i])}, function(){ | ||
this.setState({current: new Hobby(this.hobbies[i])}, function(){ | ||
this.setState(void(0), {busy: true}); | ||
@@ -118,2 +118,8 @@ }.bind(this)); | ||
getHobbies: function(person){ | ||
return DataService.getHobbiesData(person.id).map(function(hobby){ | ||
return new Hobby(hobby, true); | ||
}.bind(this)); | ||
}, | ||
deleteHobby: function(value){ | ||
@@ -145,2 +151,2 @@ /* | ||
return hobbiesViewModel; | ||
}()); | ||
})(); |
@@ -8,3 +8,3 @@ /*jshint unused: false */ | ||
var personStateChangedHandler = function(nextState, prevState/*, callback*/){ | ||
var personStateChangedHandler = function(nextState/*, callback*/){ | ||
var persons = {}; | ||
@@ -17,3 +17,3 @@ persons.collection = this.collection.map(function(person){ | ||
return person; | ||
}.bind(this)); | ||
}); | ||
this.setState(persons); | ||
@@ -30,2 +30,3 @@ }; | ||
var nextState = {}; | ||
nextState.collection = DataService.getPersonData().map(function(person, idx){ | ||
@@ -119,2 +120,2 @@ if (idx === 0){ | ||
return personsViewModel; | ||
}()); | ||
})(); |
{ | ||
"name": "imvvm", | ||
"description": "Immutable MVVM for React", | ||
"version": "0.6.20", | ||
"version": "0.7.0", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "mvvm", |
@@ -140,3 +140,3 @@ IMVVM | ||
```javascript | ||
var personStateChangedHandler = function(nextState, prevState){ | ||
var personStateChangedHandler = function(nextState){ | ||
var persons = {}; | ||
@@ -722,3 +722,3 @@ persons.collection = this.collection.map(function(person){ | ||
___ | ||
#####void ModelStateChangedHandler(object nextState,object previousState[, function callback]) | ||
#####void ModelStateChangedHandler(object nextState[, function callback]) | ||
@@ -731,10 +731,6 @@ *arguments* | ||
__previousState__ | ||
Previous state of the model. | ||
__callback__ | ||
```javascript | ||
personStateChangedHandler: function(nextState, prevState){ | ||
personStateChangedHandler: function(nextState){ | ||
var persons = {}; | ||
@@ -741,0 +737,0 @@ persons.collection = this.collection.map(function(person){ |
@@ -271,3 +271,2 @@ | ||
} | ||
} | ||
@@ -315,5 +314,3 @@ for(watchedProp in watchedState[watchedItem].fields){ | ||
Object.freeze(appState); | ||
console.warn('\"this.extend\" has been deprecated and will not be available in 0.7. Please use \"IMVVM.extend\".'); | ||
return appState; | ||
}; |
@@ -97,6 +97,2 @@ | ||
} | ||
/* deprecated - to be removed */ | ||
if(!('extend' in proto)){ | ||
proto.extend = utils.extend; | ||
} | ||
@@ -103,0 +99,0 @@ if(!!Object.keys(viewModels).length){ |
@@ -9,3 +9,3 @@ | ||
var desc = this.getDescriptor(this); | ||
var desc = this.getDescriptor(); | ||
desc.proto.setState = stateChangedHandler; | ||
@@ -12,0 +12,0 @@ |
@@ -9,7 +9,5 @@ | ||
var desc = this.getDescriptor(this); | ||
desc.stateChangedHandler = stateChangedHandler; | ||
var desc = this.getDescriptor(); | ||
var dataContext = function(nextState, extendState, initialize) { | ||
var freezeFields = desc.freezeFields, | ||
@@ -68,2 +66,6 @@ fld, | ||
model.__stateChangedHandler = (function(){ | ||
return stateChangedHandler; | ||
})(); | ||
return Object.freeze(model); | ||
@@ -70,0 +72,0 @@ }; |
@@ -51,2 +51,6 @@ | ||
tempModel.__stateChangedHandler = (function(fld){ | ||
return viewModel[fld].__stateChangedHandler; | ||
})(freezeFields[fld].fieldName); | ||
Object.defineProperty(tempModel, 'state', { | ||
@@ -59,6 +63,5 @@ configurable: true, | ||
tempModel.__proto__.setState = function(someState, callback){ //callback may be useful for DB updates | ||
return tempDesc.stateChangedHandler.call(this, | ||
extend(tempModel.state, someState), tempModel.state, callback); | ||
}.bind(viewModel); | ||
tempModel.__proto__.setState = function(state, callback){ //callback may be useful for DB updates | ||
this.__stateChangedHandler.call(viewModel, extend(this.state, state), callback); | ||
}; | ||
@@ -65,0 +68,0 @@ Object.freeze(viewModel[freezeFields[fld].fieldName]); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
177151
2639
937