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

higher order store functions

parent c476fa75
...@@ -143,6 +143,24 @@ Store.prototype = { ...@@ -143,6 +143,24 @@ Store.prototype = {
}, },
bind: function (key) { bind: function (key) {
return new StoreBinding(this, 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){ const StoreBinding = function(store, key){
......
...@@ -3,7 +3,7 @@ export default D.declare('view.page.Account', ()=> ...@@ -3,7 +3,7 @@ export default D.declare('view.page.Account', ()=>
<div> <div>
Account Page Account Page
<div> <div>
Hello, {_=>store.sub('account.name', account=> _(account))} Hello, {store.val('account.name')}
</div> </div>
</div> </div>
) )
...@@ -21,7 +21,7 @@ export default D.declare('view.page.Login', () => { ...@@ -21,7 +21,7 @@ export default D.declare('view.page.Login', () => {
<view.cmp.field.LabeledField label={'Login'} bind={loginStore.bind('phone')}/>, <view.cmp.field.LabeledField label={'Login'} bind={loginStore.bind('phone')}/>,
<button <button
onclick={()=>loginStore.set('active', 'enterCode')} onclick={()=>loginStore.set('active', 'enterCode')}
disabled={_=>loginStore.equal('phoneValid', false, _)} disabled={loginStore.valFalse('phoneValid')}
>Ага</button> >Ага</button>
], ],
enterCode: [ 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