1 Star 0 Fork 0

carrot93/meteor-session-extras

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
session-extras.js 1.84 KB
一键复制 编辑 原始数据 按行查看 历史
Ted Blackman 提交于 2013-03-20 08:13 . Added isTrue and closures
_.extend(Session,{
isTrue: function(key) {
return Session.equals(key, true);
},
// The closures are memoized so that they will create
// at most one function for each key. This should
// prevent a memory leak if the function is called
// repeatedly.
truthTester: _.memoize(function(key) {
return function() {
return Session.isTrue(key);
};
}),
getter: _.memoize(function (key) {
return function() {
return Session.get(key);
};
}),
setter: _.memoize(function (key) {
return function(value) {
return Session.set(key, value);
};
}),
whenTrue: function(keys,callback,repeat) {
if (typeof repeat === 'undefined' || repeat == null) {
repeat = false;
}
if (typeof keys === 'string') {
keys = [keys];
}
Deps.autorun(function(computation){
var allTrue = _.all(keys,function(key){
return Session.equals(key,true);
});
if (allTrue) {
callback();
!repeat && computation.stop();
}
});
},
whenFalse: function(keys,callback,repeat) {
if (typeof repeat === 'undefined' || repeat == null) {
repeat = false;
}
if (typeof keys === 'string') {
keys = [keys];
}
Deps.autorun(function(computation){
var allFalse = _.all(keys,function(key){
return ! Session.equals(key,true);
});
if (allFalse) {
callback();
!repeat && computation.stop();
}
});
},
whenEqual: function(keysAndValues,callback,repeat){
if (typeof repeat === 'undefined' || repeat == null) {
repeat = false;
}
Deps.autorun(function(computation){
var allEqual = _.all(_.keys(keysAndValues),function(key){
return Session.equals(key,keysAndValues[key]);
});
if (allEqual) {
callback();
!repeat && computation.stop();
}
});
},
});
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/carrot93/meteor-session-extras.git
git@gitee.com:carrot93/meteor-session-extras.git
carrot93
meteor-session-extras
meteor-session-extras
master

搜索帮助