Make UI.ReactiveVar public

This commit is contained in:
David Greenspan
2014-08-18 17:34:35 -07:00
parent 27c544ee05
commit f5883827ae
4 changed files with 15 additions and 15 deletions

View File

@@ -7,7 +7,7 @@ Blaze._calculateCondition = function (cond) {
Blaze.With = function (data, contentFunc) {
var view = Blaze.View('with', contentFunc);
view.dataVar = new Blaze._ReactiveVar;
view.dataVar = new Blaze.ReactiveVar;
view.onViewCreated(function () {
if (typeof data === 'function') {
@@ -24,7 +24,7 @@ Blaze.With = function (data, contentFunc) {
};
Blaze.If = function (conditionFunc, contentFunc, elseFunc, _not) {
var conditionVar = new Blaze._ReactiveVar;
var conditionVar = new Blaze.ReactiveVar;
var view = Blaze.View(_not ? 'unless' : 'if', function () {
return conditionVar.get() ? contentFunc() :
@@ -61,7 +61,7 @@ Blaze.Each = function (argFunc, contentFunc, elseFunc) {
eachView.stopHandle = null;
eachView.contentFunc = contentFunc;
eachView.elseFunc = elseFunc;
eachView.argVar = new Blaze._ReactiveVar;
eachView.argVar = new Blaze.ReactiveVar;
eachView.onViewCreated(function () {
// We evaluate argFunc in an autorun to make sure

View File

@@ -1,5 +1,5 @@
/**
* ## [new] Blaze._ReactiveVar(initialValue, [equalsFunc])
* ## [new] Blaze.ReactiveVar(initialValue, [equalsFunc])
*
* A ReactiveVar holds a single value that can be get and set,
* such that calling `set` will invalidate any Computations that
@@ -26,17 +26,17 @@
* it into the ReactiveVar of Geoff's Lickable Forms proposal.
*/
Blaze._ReactiveVar = function (initialValue, equalsFunc) {
if (! (this instanceof Blaze._ReactiveVar))
Blaze.ReactiveVar = function (initialValue, equalsFunc) {
if (! (this instanceof Blaze.ReactiveVar))
// called without `new`
return new Blaze._ReactiveVar(initialValue, equalsFunc);
return new Blaze.ReactiveVar(initialValue, equalsFunc);
this.curValue = initialValue;
this.equalsFunc = equalsFunc;
this.dep = new Deps.Dependency;
};
Blaze._ReactiveVar._isEqual = function (oldValue, newValue) {
Blaze.ReactiveVar._isEqual = function (oldValue, newValue) {
var a = oldValue, b = newValue;
// Two values are "equal" here if they are `===` and are
// number, boolean, string, undefined, or null.
@@ -47,17 +47,17 @@ Blaze._ReactiveVar._isEqual = function (oldValue, newValue) {
(typeof a === 'string'));
};
Blaze._ReactiveVar.prototype.get = function () {
Blaze.ReactiveVar.prototype.get = function () {
if (Deps.active)
this.dep.depend();
return this.curValue;
};
Blaze._ReactiveVar.prototype.set = function (newValue) {
Blaze.ReactiveVar.prototype.set = function (newValue) {
var oldValue = this.curValue;
if ((this.equalsFunc || Blaze._ReactiveVar._isEqual)(oldValue, newValue))
if ((this.equalsFunc || Blaze.ReactiveVar._isEqual)(oldValue, newValue))
// value is same as last time
return;
@@ -65,6 +65,6 @@ Blaze._ReactiveVar.prototype.set = function (newValue) {
this.dep.changed();
};
Blaze._ReactiveVar.prototype.toString = function () {
Blaze.ReactiveVar.prototype.toString = function () {
return 'ReactiveVar{' + this.get() + '}';
};

View File

@@ -1,7 +1,7 @@
if (Meteor.isClient) {
Tinytest.add("blaze - view - callbacks", function (test) {
var R = Blaze._ReactiveVar('foo');
var R = Blaze.ReactiveVar('foo');
var buf = '';

View File

@@ -13,7 +13,7 @@ Spacebars.include = function (templateOrFunction, contentFunc, elseFunc) {
return templateOrFunction.constructView(contentFunc, elseFunc);
}
var templateVar = Blaze._ReactiveVar(null, tripleEquals);
var templateVar = Blaze.ReactiveVar(null, tripleEquals);
var view = Blaze.View('Spacebars.include', function () {
var template = templateVar.get();
if (template === null)
@@ -210,7 +210,7 @@ Spacebars.dot = function (value, id1/*, id2, ...*/) {
// case, since the else block is evaluated without entering
// a new data context).
Spacebars.With = function (argFunc, contentFunc, elseFunc) {
var argVar = new Blaze._ReactiveVar;
var argVar = new Blaze.ReactiveVar;
var view = Blaze.View('Spacebars_with', function () {
return Blaze.If(function () { return argVar.get(); },
function () { return Blaze.With(function () {