Commit 3f4e7c92 by Иван Кубота

higher order store functions

parent c476fa75
......@@ -143,6 +143,24 @@ Store.prototype = {
},
bind: function (key) {
return new StoreBinding(this, key);
},
val: function(key) {
const me = this;
return function backwardCallback(update) {
me.sub(key, val => update(val));
}
},
valEqual: function(key, val) {
const me = this;
return function backwardCallback(update) {
me.equal(key, val, compareResult => update(compareResult));
}
},
valTrue: function(key) {
return this.valEqual(key, true);
},
valFalse: function(key) {
return this.valEqual(key, false);
}
};
const StoreBinding = function(store, key){
......
......@@ -3,7 +3,7 @@ export default D.declare('view.page.Account', ()=>
<div>
Account Page
<div>
Hello, {_=>store.sub('account.name', account=> _(account))}
Hello, {store.val('account.name')}
</div>
</div>
)
......@@ -21,7 +21,7 @@ export default D.declare('view.page.Login', () => {
<view.cmp.field.LabeledField label={'Login'} bind={loginStore.bind('phone')}/>,
<button
onclick={()=>loginStore.set('active', 'enterCode')}
disabled={_=>loginStore.equal('phoneValid', false, _)}
disabled={loginStore.valFalse('phoneValid')}
>Ага</button>
],
enterCode: [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment