Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

imvvm

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imvvm - npm Package Compare versions

Comparing version 0.4.0-alpha to 0.4.1-alpha

2

bower.json
{
"name": "imvvm",
"version": "0.4.0-alpha",
"version": "0.4.1-alpha",
"homepage": "https://github.com/entrendipity/imvvm",

@@ -5,0 +5,0 @@ "authors": [

@@ -23,3 +23,4 @@ !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){

watchList = {},
domain;
domain,
reprocessing = false;

@@ -97,3 +98,4 @@ disableUndo === void(0) ? false : disableUndo;

newStateKeysLen,
subscriberKeys;
subscriberKeys,
rollback = false;

@@ -116,2 +118,3 @@ initialize === void(0) ? false : initialize;

prevState = newState.previousState;
rollback = true;
} else {

@@ -137,3 +140,3 @@ if(caller in watchList){

nextState[caller] = newState;
nextState = extend(thisAppState, nextState);
nextState = extend(thisAppState.state, nextState);
} else {

@@ -144,7 +147,7 @@ //appDataContext is calling function

} else {
nextState = extend(thisAppState, newState);
nextState = extend(thisAppState.state, newState);
}
}
prevState = thisAppState;
nextState = transitionState(nextState, thisAppState, watchedDataContext);
prevState = reprocessing ? thisAppState.previousState : thisAppState;
nextState = transitionState(nextState, thisAppState.state, watchedDataContext);
}

@@ -154,16 +157,29 @@ prevState = prevState || {};

//Create a new App state context. Only pass in previous state if it is actually an ApplicationDataContext
thisAppState = new ApplicationDataContext(nextState, prevState, disableUndo, initialize);
Object.freeze(thisAppState);
//Create a new App state context.
thisAppState = new ApplicationDataContext(nextState, prevState, disableUndo);
if(!!thisAppState.validateState && !rollback && !reprocessing) {
var validationObj = thisAppState.validateState(thisAppState.state, thisAppState.previousState);
var validationKeys = Object.keys(validationObj);
for (var keyIdx = validationKeys.length - 1; keyIdx >= 0; keyIdx--) {
if(Object.prototype.toString.call(validationObj[validationKeys[keyIdx]]) !== '[object Object]' &&
Object.prototype.toString.call(validationObj[validationKeys[keyIdx]]) !== '[object Array]' &&
validationObj[validationKeys[keyIdx]] !== thisAppState.state[validationKeys[keyIdx]]){
reprocessing = true;
thisAppState.setState(extend(thisAppState.state, validationObj));
reprocessing = false;
break;
}
};
}
//All the work is done! -> Notify the View
stateChangedHandler(thisAppState, caller, callback);
//Provided for the main app to return from init() to the View
//return appContext;
return thisAppState;
if(!reprocessing){
Object.freeze(thisAppState);
stateChangedHandler(thisAppState, caller, callback);
return thisAppState;
}
};
ApplicationDataContext = domainModel.call(this, appStateChangedHandler.bind(this, appNamespace));
var applicationDataContext = new ApplicationDataContext({}, {}, disableUndo, true);
var applicationDataContext = new ApplicationDataContext({}, {}, disableUndo);
domain = applicationDataContext.dataContexts();

@@ -283,3 +299,3 @@ for(var dataContext in domain){

var dataContext = function(nextState, prevState, disableUndo, initialize) {
var dataContext = function(nextState, prevState, disableUndo) {
var initFunc;

@@ -300,3 +316,3 @@ var calcFld;

}
var model = Object.create(desc.proto, desc.descriptor);

@@ -328,16 +344,9 @@

if(!initialize){
//runs everytime after initialized
if(desc.originalSpec.validateState){
nextState = extend(nextState,
desc.originalSpec.validateState.call(model, nextState, prevState));
}
if(!disableUndo && !!Object.keys(prevState).length){
Object.defineProperty(nextState, 'previousState', {
configurable: false,
enumerable: false,
writable: false,
value: prevState
});
}
if(!disableUndo && !!Object.keys(prevState).length){
Object.defineProperty(nextState, 'previousState', {
configurable: false,
enumerable: false,
writable: false,
value: prevState
});
}

@@ -556,3 +565,3 @@

for(var dep in dependencies){
if(dependencies.hasOwnProperty(dep)){
if(dependencies.hasOwnProperty(dep) && dep[0] !== '_'){
Object.defineProperty(model, dep, {

@@ -559,0 +568,0 @@ configurable: false,

@@ -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(k,p,t,x){if(typeof t!=="function"){throw new TypeError()}var w,v={},j={},u,n={},q;x===void (0)?false:x;var o=function(B,F,D){var G=false,E,A;F=F||{};if(B===void (0)){A=true;B={}}var C=function(I){var K={},J,H;if("dependsOn" in I){I.dependsOn.forEach(function(L){H={};J=L.property.split(".");J.forEach(function(N,M){if(M===0){H=B[N]}else{H=H?H[N]:void (0)}});if("alias" in L){K[L.alias]=H}else{K[J.join("$")]=H}})}return K};for(var z in q){if(q.hasOwnProperty(z)){E=C(q[z]);if(A){B[z]=new j[z](B[z],E,F[z]).getInitialState()}else{B[z]=new j[z](B[z],E,F[z])}if(D){if(G&&D.subscribers.indexOf(z)!==-1){E=C(q[D.name]);B[D.name]=new j[D.name](B[D.name],E,F[D.name])}G=G?G:z===D.name}}}return B};var m=function(z,A,H,E){var K={},G={},J=void (0),F,D,I;E===void (0)?false:E;if(!E&&(A===void (0)||A===null||Object.keys(A).length===0)){return}var C=!!A?Object.getPrototypeOf(A).constructor.classType==="DomainModel":false;if(C){K=i(A);G=A.previousState}else{if(z in n){F=Object.keys(A);D=F.length;I={};for(var B=0;B<D;B++){if(n[z][F[B]]){I[n[z][F[B]]]=true}}J={};J.name=z;J.subscribers=Object.keys(I);J=!!J.subscribers.length?J:void (0)}if(z!==k){K[z]=A;K=i(v,K)}else{if(E){K=i(o(),A)}else{K=i(v,A)}}G=v;K=o(K,v,J)}G=G||{};Object.freeze(G);v=new w(K,G,x,E);Object.freeze(v);t(v,z,H);return v};w=p.call(this,m.bind(this,k));var y=new w({},{},x,true);q=y.dataContexts();for(var l in q){if(q.hasOwnProperty(l)){j[l]=q[l].viewModel.call(this,m.bind(this,l));if("dependsOn" in q[l]){for(var r=0,s=q[l].dependsOn.length;r<s;r++){u=q[l].dependsOn[r].property.split(".");if(u.length>1){n[u[0]]=n[u[0]]||{};n[u[0]][u[1]]=n[u[0]][u[1]]||[];if(n[u[0]][u[1]].indexOf(l)===-1){n[u[0]][u[1]].push(l)}}}}}}return y.getInitialState()}},{"./utils":8}],3:[function(f,g,j){var k=f("./imvvmModel");var p=f("./imvvmViewModel");var i=f("./imvvmDomainModel");var r=f("./mixin");var q=f("./utils");var n=q.extend;var m=q.mixInto;var l=function(){};var h=function(){};var o=function(){};m(l,k.Mixin);m(h,p.Mixin);m(o,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;return w}};var s={createModel:e.createClass.bind(this,l,"Model"),createViewModel:e.createClass.bind(this,h,"ViewModel"),createDomainModel:e.createClass.bind(this,o,"DomainModel"),mixin:r};g.exports=s},{"./imvvmDomainModel":4,"./imvvmModel":5,"./imvvmViewModel":6,"./mixin":7,"./utils":8}],4:[function(j,h,f){var e=j("./utils");var k=e.extend;var g=e.getDescriptor;var i={Mixin:{construct:function(m){var o=g.call(this);o.proto.setState=m;var n=function(p,q){return o.proto.setState(p,q,true)};var l=function(x,v,w,r){var u;var t;x=x||{};v=v||{};if(!("getInitialState" in o.proto)){o.proto.getInitialState=function(){return n()}}else{u=o.proto.getInitialState;o.proto.getInitialState=function(){return n(u.call(this))}}var s=Object.create(o.proto,o.descriptor);Object.defineProperty(s,"state",{configurable:true,enumerable:false,writable:true,value:x});x=k(x,s);if(!!o.originalSpec.getInitialCalculatedState){for(var q=o.calculatedFields.length-1;q>=0;q--){if(!(o.calculatedFields[q] in x)||x[o.calculatedFields[q]]===void (0)){t={};t[o.calculatedFields[q]]=o.originalSpec.getInitialCalculatedState.call(s,x,v)[o.calculatedFields[q]];if(t[o.calculatedFields[q]]!==void (0)){x=k(x,t)}}}}if(!r){if(o.originalSpec.validateState){x=k(x,o.originalSpec.validateState.call(s,x,v))}if(!w&&!!Object.keys(v).length){Object.defineProperty(x,"previousState",{configurable:false,enumerable:false,writable:false,value:v})}}Object.defineProperty(x,"state",{configurable:false,enumerable:false,writable:false,value:k(x)});for(var p in o.descriptor){if(o.descriptor.hasOwnProperty(p)){Object.defineProperty(x,p,o.descriptor[p])}}x.__proto__=s.__proto__;return x};return l}}};h.exports=i},{"./utils":8}],5:[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(s,u,o){var p=Object.create(n.proto,n.descriptor);var v=arguments.length;var r=typeof Array.prototype.slice.call(arguments,-1)[0]==="boolean";var t;if(v===0){s={};u={};o=true}else{if(v===1){if(r){o=s;s={};u={}}else{u=s;o=true}}else{if(v===2){if(r){o=u;u=s}else{o=true}}}}s=("state" in s)?s.state:s;u=("state" in u)?u.state:u;Object.defineProperty(p,"state",{configurable:true,enumerable:false,writable:true,value:s});s=k(s,p);if(!!n.originalSpec.getInitialCalculatedState){for(var q=n.calculatedFields.length-1;q>=0;q--){if(!(n.calculatedFields[q] in s)||s[n.calculatedFields[q]]===void (0)){t={};t[n.calculatedFields[q]]=n.originalSpec.getInitialCalculatedState.call(p,s,u)[n.calculatedFields[q]];if(t[n.calculatedFields[q]]!==void (0)){s=k(s,t)}}}}if(n.originalSpec.validateState){s=k(s,n.originalSpec.validateState.call(p,s,u))}if(o){Object.defineProperty(p,"context",{configurable:true,enumerable:true,set:function(w){this.setState=function(x,y){return m.bind(w).call(w,k(this.state,x),this.state,y)}.bind(this);delete this.context}})}Object.defineProperty(p,"state",{configurable:false,enumerable:false,writable:false,value:s});if(!o){Object.freeze(p)}return p};return l}}};h.exports=j},{"./utils":8}],6:[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(q,r,u){var v;var t;q=k(q,r);u=u||{};u=("state" in u)?u.state:u;if(!("getInitialState" in n.proto)){n.proto.getInitialState=function(){return l()}}else{v=n.proto.getInitialState;n.proto.getInitialState=function(){return l(v.call(this))}}var o=Object.create(n.proto,n.descriptor);Object.defineProperty(o,"state",{configurable:true,enumerable:false,writable:true,value:q});q=k(q,o);if(!!n.originalSpec.getInitialCalculatedState){for(var p=n.calculatedFields.length-1;p>=0;p--){if(!(n.calculatedFields[p] in q)||q[n.calculatedFields[p]]===void (0)){t={};t[n.calculatedFields[p]]=n.originalSpec.getInitialCalculatedState.call(o,q,u)[n.calculatedFields[p]];if(t[n.calculatedFields[p]]!==void (0)){q=k(q,t)}}}}if(n.originalSpec.validateState){q=k(q,n.originalSpec.validateState.call(o,q,u))}Object.defineProperty(o,"state",{configurable:false,enumerable:false,writable:false,value:q});Object.keys(o).forEach(function(w){if(Object.prototype.toString.call(this[w])==="[object Object]"&&("context" in this[w])){this[w].context=this;Object.freeze(this[w])}else{if(Object.prototype.toString.call(this[w])==="[object Array]"){Object.freeze(this[w])}}}.bind(o));for(var s in r){if(r.hasOwnProperty(s)){Object.defineProperty(o,s,{configurable:false,enumerable:false,writable:false,value:r[s]})}}Object.freeze(q);return o};return l}}};i.exports=e},{"./utils":8}],7:[function(j,i,h){var f=j("./core");var e="__IMVVM__";var g={stateChangedHandler:function(k,l,m){this.setState({applicationDataContext:k},function(){if(typeof m==="function"){if(this.state===null||!("applicationDataContext" in this.state)){m(void (0))}else{if(l in this.state.applicationDataContext){m(this.state.applicationDataContext[l])}else{if(l===e){m(this.state.applicationDataContext)}else{m(void (0))}}}}}.bind(this))},getInitialState:function(){var k=f.getInitialState(e,this.props.domainModel,this.stateChangedHandler,this.props.disableUndo);return{applicationDataContext:k}}};i.exports=g},{"./core":2}],8:[function(h,g,f){var e={getDescriptor:function(){var l={};var k=this.prototype;var i=[];for(var j in this.originalSpec){if(this.originalSpec.hasOwnProperty(j)){if("get" in this.originalSpec[j]||"set" in this.originalSpec[j]){if("calculated" in this.originalSpec[j]){l[j]=e.extend(this.originalSpec[j]);l[j].enumerable=!this.originalSpec[j].calculated;delete l[j].calculated;i.push(j)}else{if(!("enumerable" in this.originalSpec[j])){this.originalSpec[j].enumerable=true;l[j]=this.originalSpec[j]}else{l[j]=this.originalSpec[j]}}}else{k[j]=this.originalSpec[j]}}}if(!("extend" in k)){k.extend=e.extend}return{descriptor:l,proto:k,originalSpec:this.originalSpec||{},calculatedFields:i}},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(k,p,u,y){if(typeof u!=="function"){throw new TypeError()}var x,w={},j={},v,n={},q,t=false;y===void (0)?false:y;var o=function(C,G,E){var H=false,F,B;G=G||{};if(C===void (0)){B=true;C={}}var D=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=C[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 A in q){if(q.hasOwnProperty(A)){F=D(q[A]);if(B){C[A]=new j[A](C[A],F,G[A]).getInitialState()}else{C[A]=new j[A](C[A],F,G[A])}if(E){if(H&&E.subscribers.indexOf(A)!==-1){F=D(q[E.name]);C[E.name]=new j[E.name](C[E.name],F,G[E.name])}H=H?H:A===E.name}}}return C};var m=function(C,E,M,I){var P={},L={},O=void (0),J,H,N,K=false;I===void (0)?false:I;if(!I&&(E===void (0)||E===null||Object.keys(E).length===0)){return}var G=!!E?Object.getPrototypeOf(E).constructor.classType==="DomainModel":false;if(G){P=i(E);L=E.previousState;K=true}else{if(C in n){J=Object.keys(E);H=J.length;N={};for(var F=0;F<H;F++){if(n[C][J[F]]){N[n[C][J[F]]]=true}}O={};O.name=C;O.subscribers=Object.keys(N);O=!!O.subscribers.length?O:void (0)}if(C!==k){P[C]=E;P=i(w.state,P)}else{if(I){P=i(o(),E)}else{P=i(w.state,E)}}L=t?w.previousState:w;P=o(P,w.state,O)}L=L||{};Object.freeze(L);w=new x(P,L,y);if(!!w.validateState&&!K&&!t){var B=w.validateState(w.state,w.previousState);var A=Object.keys(B);for(var D=A.length-1;D>=0;D--){if(Object.prototype.toString.call(B[A[D]])!=="[object Object]"&&Object.prototype.toString.call(B[A[D]])!=="[object Array]"&&B[A[D]]!==w.state[A[D]]){t=true;w.setState(i(w.state,B));t=false;break}}}if(!t){Object.freeze(w);u(w,C,M);return w}};x=p.call(this,m.bind(this,k));var z=new x({},{},y);q=z.dataContexts();for(var l in q){if(q.hasOwnProperty(l)){j[l]=q[l].viewModel.call(this,m.bind(this,l));if("dependsOn" in q[l]){for(var r=0,s=q[l].dependsOn.length;r<s;r++){v=q[l].dependsOn[r].property.split(".");if(v.length>1){n[v[0]]=n[v[0]]||{};n[v[0]][v[1]]=n[v[0]][v[1]]||[];if(n[v[0]][v[1]].indexOf(l)===-1){n[v[0]][v[1]].push(l)}}}}}}return z.getInitialState()}},{"./utils":8}],3:[function(f,g,j){var k=f("./imvvmModel");var p=f("./imvvmViewModel");var i=f("./imvvmDomainModel");var r=f("./mixin");var q=f("./utils");var n=q.extend;var m=q.mixInto;var l=function(){};var h=function(){};var o=function(){};m(l,k.Mixin);m(h,p.Mixin);m(o,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;return w}};var s={createModel:e.createClass.bind(this,l,"Model"),createViewModel:e.createClass.bind(this,h,"ViewModel"),createDomainModel:e.createClass.bind(this,o,"DomainModel"),mixin:r};g.exports=s},{"./imvvmDomainModel":4,"./imvvmModel":5,"./imvvmViewModel":6,"./mixin":7,"./utils":8}],4:[function(j,h,f){var e=j("./utils");var k=e.extend;var g=e.getDescriptor;var i={Mixin:{construct:function(m){var o=g.call(this);o.proto.setState=m;var n=function(p,q){return o.proto.setState(p,q,true)};var l=function(t,v,p){var w;var u;t=t||{};v=v||{};if(!("getInitialState" in o.proto)){o.proto.getInitialState=function(){return n()}}else{w=o.proto.getInitialState;o.proto.getInitialState=function(){return n(w.call(this))}}var r=Object.create(o.proto,o.descriptor);Object.defineProperty(r,"state",{configurable:true,enumerable:false,writable:true,value:t});t=k(t,r);if(!!o.originalSpec.getInitialCalculatedState){for(var s=o.calculatedFields.length-1;s>=0;s--){if(!(o.calculatedFields[s] in t)||t[o.calculatedFields[s]]===void (0)){u={};u[o.calculatedFields[s]]=o.originalSpec.getInitialCalculatedState.call(r,t,v)[o.calculatedFields[s]];if(u[o.calculatedFields[s]]!==void (0)){t=k(t,u)}}}}if(!p&&!!Object.keys(v).length){Object.defineProperty(t,"previousState",{configurable:false,enumerable:false,writable:false,value:v})}Object.defineProperty(t,"state",{configurable:false,enumerable:false,writable:false,value:k(t)});for(var q in o.descriptor){if(o.descriptor.hasOwnProperty(q)){Object.defineProperty(t,q,o.descriptor[q])}}t.__proto__=r.__proto__;return t};return l}}};h.exports=i},{"./utils":8}],5:[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(s,u,o){var p=Object.create(n.proto,n.descriptor);var v=arguments.length;var r=typeof Array.prototype.slice.call(arguments,-1)[0]==="boolean";var t;if(v===0){s={};u={};o=true}else{if(v===1){if(r){o=s;s={};u={}}else{u=s;o=true}}else{if(v===2){if(r){o=u;u=s}else{o=true}}}}s=("state" in s)?s.state:s;u=("state" in u)?u.state:u;Object.defineProperty(p,"state",{configurable:true,enumerable:false,writable:true,value:s});s=k(s,p);if(!!n.originalSpec.getInitialCalculatedState){for(var q=n.calculatedFields.length-1;q>=0;q--){if(!(n.calculatedFields[q] in s)||s[n.calculatedFields[q]]===void (0)){t={};t[n.calculatedFields[q]]=n.originalSpec.getInitialCalculatedState.call(p,s,u)[n.calculatedFields[q]];if(t[n.calculatedFields[q]]!==void (0)){s=k(s,t)}}}}if(n.originalSpec.validateState){s=k(s,n.originalSpec.validateState.call(p,s,u))}if(o){Object.defineProperty(p,"context",{configurable:true,enumerable:true,set:function(w){this.setState=function(x,y){return m.bind(w).call(w,k(this.state,x),this.state,y)}.bind(this);delete this.context}})}Object.defineProperty(p,"state",{configurable:false,enumerable:false,writable:false,value:s});if(!o){Object.freeze(p)}return p};return l}}};h.exports=j},{"./utils":8}],6:[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(q,r,u){var v;var t;q=k(q,r);u=u||{};u=("state" in u)?u.state:u;if(!("getInitialState" in n.proto)){n.proto.getInitialState=function(){return l()}}else{v=n.proto.getInitialState;n.proto.getInitialState=function(){return l(v.call(this))}}var o=Object.create(n.proto,n.descriptor);Object.defineProperty(o,"state",{configurable:true,enumerable:false,writable:true,value:q});q=k(q,o);if(!!n.originalSpec.getInitialCalculatedState){for(var p=n.calculatedFields.length-1;p>=0;p--){if(!(n.calculatedFields[p] in q)||q[n.calculatedFields[p]]===void (0)){t={};t[n.calculatedFields[p]]=n.originalSpec.getInitialCalculatedState.call(o,q,u)[n.calculatedFields[p]];if(t[n.calculatedFields[p]]!==void (0)){q=k(q,t)}}}}if(n.originalSpec.validateState){q=k(q,n.originalSpec.validateState.call(o,q,u))}Object.defineProperty(o,"state",{configurable:false,enumerable:false,writable:false,value:q});Object.keys(o).forEach(function(w){if(Object.prototype.toString.call(this[w])==="[object Object]"&&("context" in this[w])){this[w].context=this;Object.freeze(this[w])}else{if(Object.prototype.toString.call(this[w])==="[object Array]"){Object.freeze(this[w])}}}.bind(o));for(var s in r){if(r.hasOwnProperty(s)&&s[0]!=="_"){Object.defineProperty(o,s,{configurable:false,enumerable:false,writable:false,value:r[s]})}}Object.freeze(q);return o};return l}}};i.exports=e},{"./utils":8}],7:[function(j,i,h){var f=j("./core");var e="__IMVVM__";var g={stateChangedHandler:function(k,l,m){this.setState({applicationDataContext:k},function(){if(typeof m==="function"){if(this.state===null||!("applicationDataContext" in this.state)){m(void (0))}else{if(l in this.state.applicationDataContext){m(this.state.applicationDataContext[l])}else{if(l===e){m(this.state.applicationDataContext)}else{m(void (0))}}}}}.bind(this))},getInitialState:function(){var k=f.getInitialState(e,this.props.domainModel,this.stateChangedHandler,this.props.disableUndo);return{applicationDataContext:k}}};i.exports=g},{"./core":2}],8:[function(h,g,f){var e={getDescriptor:function(){var l={};var k=this.prototype;var i=[];for(var j in this.originalSpec){if(this.originalSpec.hasOwnProperty(j)){if("get" in this.originalSpec[j]||"set" in this.originalSpec[j]){if("calculated" in this.originalSpec[j]){l[j]=e.extend(this.originalSpec[j]);l[j].enumerable=!this.originalSpec[j].calculated;delete l[j].calculated;i.push(j)}else{if(!("enumerable" in this.originalSpec[j])){this.originalSpec[j].enumerable=true;l[j]=this.originalSpec[j]}else{l[j]=this.originalSpec[j]}}}else{k[j]=this.originalSpec[j]}}}if(!("extend" in k)){k.extend=e.extend}return{descriptor:l,proto:k,originalSpec:this.originalSpec||{},calculatedFields:i}},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)});
/*jshint unused: vars */
/*jshint unused: false */
/* global IMVVM */
/* global IMVVM, HobbiesViewModel, PersonsViewModel */

@@ -11,6 +11,17 @@ 'use strict';

return {
online: true,
online: true
};
},
getInitialCalculatedState: function(nextState, prevState){
return {
busy: false
};
},
validateState: function(nextState, prevState){
if(!!nextState.hobbies.selected){
return {busy: true};
} else {
return {busy: false};
}
},

@@ -22,7 +33,17 @@ undo: function(){

busy: {
calculated: true,
get: function(){
return this.state.busy;
},
// set: function(newValue){
// this.setState({'busy': newValue });
// }
},
online: {
get: function(){
return this.state.online;
},
set: function(newValue){
this.setState({'busy': newValue });
this.setState({'online': newValue });
}

@@ -35,14 +56,12 @@ },

viewModel: HobbiesViewModel,
initArgs : [],
dependsOn: [{property: 'persons.selected'},
{property: 'busy', alias: 'appIsBusy'}]
dependsOn: [{property: 'persons.selected', alias: '_selectedPerson'},
{property: 'busy', alias: '_busy'}]
},
persons: {
viewModel: PersonsViewModel,
initArgs : [],
dependsOn: [{property: 'hobbies.selected', alias: 'selectedHobby'},
dependsOn: [{property: 'hobbies.selected'},
{property: 'online', alias: 'imOnline'}]
}
}
};
}
});

@@ -9,3 +9,3 @@ /*jshint unused: false */

var nextState = {};
nextState.selected = this.persons$selected.hobbies.filter(function(hobby){
nextState.selected = this.hobbies.filter(function(hobby){
return hobby === value;

@@ -17,7 +17,7 @@ })[0];

addHobby: function(value){
this.persons$selected.addHobby(value);
this.state._selectedPerson.addHobby(value);
},
deleteHobby: function(value){
this.persons$selected.deleteHobby(value);
this.state._selectedPerson.deleteHobby(value);
},

@@ -27,4 +27,4 @@

resetSelected: function(nextState, prevState) {
if(prevState.persons$selected && nextState.persons$selected){
if(nextState.persons$selected.id !== prevState.persons$selected.id &&
if(prevState._selectedPerson && nextState._selectedPerson){
if(nextState._selectedPerson.id !== prevState._selectedPerson.id &&
nextState.selected !== void(0)){

@@ -37,2 +37,9 @@ return void(0);

hobbies: {
enumerable: false,
get: function(){
return this.state._selectedPerson.hobbies;
}
},
validateState: function(nextState, prevState){

@@ -44,2 +51,8 @@ return {

busyText: {
get: function(){
return this.state._busy ? 'Im Busy! Go away...' : 'Not doing too much.';
}
},
selected: {

@@ -46,0 +59,0 @@ get: function(){

@@ -23,5 +23,4 @@ /**

var app = this.props.appContext;
var collection = this.props.appContext.hobbies.persons$selected.hobbies;
var collection = this.props.appContext.hobbies.hobbies;
var current = this.props.appContext.hobbies.selected;
var display;

@@ -53,8 +52,2 @@ var list = collection.map(function(hobby){

display = this.props.appContext.hobbies.appIsBusy ? "Im Busy! Go away..." : (
<div className="list-group">
{list}
</div>
);
return (

@@ -64,3 +57,6 @@ <div>

funcAdd={this.addHobby} />
{display}
{this.props.appContext.hobbies.busyText}
<div className="list-group">
{list}
</div>
</div>

@@ -67,0 +63,0 @@ );

@@ -22,2 +22,3 @@ /**

var current = this.props.appContext.persons.selected;
var selectedHobby = !!this.props.appContext.persons.hobbies$selected ? " is " + this.props.appContext.persons.hobbies$selected : "";

@@ -32,3 +33,3 @@ var list = collection.map(function(person){

className="list-group-item active">
{person.fullName}
{this.props.appContext.persons.imOnline ? "" : "Offline -> "} {person.fullName + selectedHobby}
<DeleteButton funcDelete={this.deletePerson.bind(this, person.id)} />

@@ -43,3 +44,3 @@ </a>

className="list-group-item">
{person.fullName}
{this.props.appContext.persons.imOnline ? "" : "Offline -> "} {person.fullName}
<DeleteButton funcDelete={this.deletePerson.bind(this, person.id)} />

@@ -46,0 +47,0 @@ </a>

@@ -20,10 +20,10 @@ /**

},
toggleBusyState: function(e){
toggleOnlineState: function(e){
e.preventDefault();
e.stopPropagation();
this.props.appContext.busy = !this.props.appContext.busy;
this.props.appContext.online = !this.props.appContext.online;
},
render: function(){
var busyBtnTxt = this.props.appContext.busy ? "Stop Now" : "Get Busy";
var onlineBtnTxt = this.props.appContext.online ? "Go offline" : "Go online";
var onlineBtnClass = this.props.appContext.online ? "btn btn-success": "btn btn-danger";
return (

@@ -50,4 +50,4 @@ <nav className="navbar navbar-default" role="navigation">

</button>
<button onClick={this.toggleBusyState} className="btn btn-default">
{busyBtnTxt}
<button onClick={this.toggleOnlineState} className={onlineBtnClass}>
{onlineBtnTxt}
</button>

@@ -54,0 +54,0 @@ </form>

{
"name": "imvvm",
"description": "Immutable MVVM for React",
"version": "0.4.0-alpha",
"version": "0.4.1-alpha",
"keywords": [

@@ -6,0 +6,0 @@ "imvvm",

@@ -16,3 +16,4 @@

watchList = {},
domain;
domain,
reprocessing = false;

@@ -90,3 +91,4 @@ disableUndo === void(0) ? false : disableUndo;

newStateKeysLen,
subscriberKeys;
subscriberKeys,
rollback = false;

@@ -109,2 +111,3 @@ initialize === void(0) ? false : initialize;

prevState = newState.previousState;
rollback = true;
} else {

@@ -130,3 +133,3 @@ if(caller in watchList){

nextState[caller] = newState;
nextState = extend(thisAppState, nextState);
nextState = extend(thisAppState.state, nextState);
} else {

@@ -137,7 +140,7 @@ //appDataContext is calling function

} else {
nextState = extend(thisAppState, newState);
nextState = extend(thisAppState.state, newState);
}
}
prevState = thisAppState;
nextState = transitionState(nextState, thisAppState, watchedDataContext);
prevState = reprocessing ? thisAppState.previousState : thisAppState;
nextState = transitionState(nextState, thisAppState.state, watchedDataContext);
}

@@ -147,16 +150,29 @@ prevState = prevState || {};

//Create a new App state context. Only pass in previous state if it is actually an ApplicationDataContext
thisAppState = new ApplicationDataContext(nextState, prevState, disableUndo, initialize);
Object.freeze(thisAppState);
//Create a new App state context.
thisAppState = new ApplicationDataContext(nextState, prevState, disableUndo);
if(!!thisAppState.validateState && !rollback && !reprocessing) {
var validationObj = thisAppState.validateState(thisAppState.state, thisAppState.previousState);
var validationKeys = Object.keys(validationObj);
for (var keyIdx = validationKeys.length - 1; keyIdx >= 0; keyIdx--) {
if(Object.prototype.toString.call(validationObj[validationKeys[keyIdx]]) !== '[object Object]' &&
Object.prototype.toString.call(validationObj[validationKeys[keyIdx]]) !== '[object Array]' &&
validationObj[validationKeys[keyIdx]] !== thisAppState.state[validationKeys[keyIdx]]){
reprocessing = true;
thisAppState.setState(extend(thisAppState.state, validationObj));
reprocessing = false;
break;
}
};
}
//All the work is done! -> Notify the View
stateChangedHandler(thisAppState, caller, callback);
//Provided for the main app to return from init() to the View
//return appContext;
return thisAppState;
if(!reprocessing){
Object.freeze(thisAppState);
stateChangedHandler(thisAppState, caller, callback);
return thisAppState;
}
};
ApplicationDataContext = domainModel.call(this, appStateChangedHandler.bind(this, appNamespace));
var applicationDataContext = new ApplicationDataContext({}, {}, disableUndo, true);
var applicationDataContext = new ApplicationDataContext({}, {}, disableUndo);
domain = applicationDataContext.dataContexts();

@@ -163,0 +179,0 @@ for(var dataContext in domain){

@@ -16,3 +16,3 @@

var dataContext = function(nextState, prevState, disableUndo, initialize) {
var dataContext = function(nextState, prevState, disableUndo) {
var initFunc;

@@ -33,3 +33,3 @@ var calcFld;

}
var model = Object.create(desc.proto, desc.descriptor);

@@ -61,16 +61,9 @@

if(!initialize){
//runs everytime after initialized
if(desc.originalSpec.validateState){
nextState = extend(nextState,
desc.originalSpec.validateState.call(model, nextState, prevState));
}
if(!disableUndo && !!Object.keys(prevState).length){
Object.defineProperty(nextState, 'previousState', {
configurable: false,
enumerable: false,
writable: false,
value: prevState
});
}
if(!disableUndo && !!Object.keys(prevState).length){
Object.defineProperty(nextState, 'previousState', {
configurable: false,
enumerable: false,
writable: false,
value: prevState
});
}

@@ -77,0 +70,0 @@

@@ -82,3 +82,3 @@

for(var dep in dependencies){
if(dependencies.hasOwnProperty(dep)){
if(dependencies.hasOwnProperty(dep) && dep[0] !== '_'){
Object.defineProperty(model, dep, {

@@ -85,0 +85,0 @@ configurable: false,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc