can-globals
Advanced tools
Comparing version 0.2.4 to 0.2.5
@@ -10,2 +10,5 @@ 'use strict'; | ||
var handlersCopy = handlers.slice(); | ||
if (typeof value === 'function') { | ||
value = value(); | ||
} | ||
for (var i = 0; i < handlersCopy.length; i++) { | ||
@@ -76,3 +79,3 @@ handlersCopy[i](value); | ||
*/ | ||
Globals.prototype.define = function(key, value, enableCache) { | ||
Globals.prototype.define = function (key, value, enableCache) { | ||
if (enableCache === undefined) { | ||
@@ -112,7 +115,7 @@ enableCache = true; | ||
*/ | ||
Globals.prototype.getKeyValue = function(key){ | ||
Globals.prototype.getKeyValue = function (key) { | ||
var property = this.properties[key]; | ||
if (property) { | ||
if (typeof property.value === 'function') { | ||
if(property.cachedValue){ | ||
if (property.cachedValue) { | ||
return property.cachedValue; | ||
@@ -131,4 +134,4 @@ } | ||
Globals.prototype.makeExport = function(key) { | ||
return function(value) { | ||
Globals.prototype.makeExport = function (key) { | ||
return function (value) { | ||
if (arguments.length === 0) { | ||
@@ -141,7 +144,7 @@ return this.getKeyValue(key); | ||
} else { | ||
if (typeof value === 'function'){ | ||
this.setKeyValue(key, function(){ | ||
if (typeof value === 'function') { | ||
this.setKeyValue(key, function () { | ||
return value; | ||
}); | ||
}else{ | ||
} else { | ||
this.setKeyValue(key, value); | ||
@@ -184,3 +187,3 @@ } | ||
*/ | ||
Globals.prototype.offKeyValue = function(key, handler) { | ||
Globals.prototype.offKeyValue = function (key, handler) { | ||
if (this.properties[key]) { | ||
@@ -223,3 +226,3 @@ var handlers = this.eventHandlers[key]; | ||
*/ | ||
Globals.prototype.onKeyValue = function(key, handler) { | ||
Globals.prototype.onKeyValue = function (key, handler) { | ||
if (this.properties[key]) { | ||
@@ -229,3 +232,3 @@ if (!this.eventHandlers[key]) { | ||
} | ||
this.eventHandlers[key].push(handler); | ||
this.eventHandlers[key].push(handler); | ||
} | ||
@@ -258,3 +261,3 @@ return this; | ||
*/ | ||
Globals.prototype.deleteKeyValue = function(key) { | ||
Globals.prototype.deleteKeyValue = function (key) { | ||
var property = this.properties[key]; | ||
@@ -296,3 +299,3 @@ if (property !== undefined) { | ||
*/ | ||
Globals.prototype.setKeyValue = function(key, value){ | ||
Globals.prototype.setKeyValue = function (key, value) { | ||
if (!this.properties[key]) { | ||
@@ -327,5 +330,5 @@ return this.define(key, value); | ||
*/ | ||
Globals.prototype.reset = function(){ | ||
for(var key in this.properties){ | ||
if(this.properties.hasOwnProperty(key)){ | ||
Globals.prototype.reset = function () { | ||
for (var key in this.properties) { | ||
if (this.properties.hasOwnProperty(key)) { | ||
this.properties[key].cachedValue = undefined; | ||
@@ -332,0 +335,0 @@ dispatch.call(this, key, this.getKeyValue(key)); |
@@ -47,2 +47,3 @@ 'use strict'; | ||
ok(true); | ||
globals.offKeyValue('test'); | ||
}); | ||
@@ -159,2 +160,3 @@ | ||
]); | ||
globals.offKeyValue('test'); | ||
}); | ||
@@ -226,2 +228,4 @@ | ||
equal(barHandler.callCount, 1); | ||
globals.offKeyValue('foo'); | ||
globals.offKeyValue('bar'); | ||
}); | ||
@@ -242,1 +246,15 @@ | ||
}); | ||
QUnit.test('onKeyValue should dispatch the resolved value (#29)', function(){ | ||
var globals = new Globals(); | ||
var foo = 'foo'; | ||
globals.define('foo', ''); | ||
globals.onKeyValue('foo', function(value){ | ||
QUnit.equal(value, foo); | ||
}); | ||
globals.setKeyValue('foo', function(){ | ||
return foo; | ||
}); | ||
globals.offKeyValue('foo'); | ||
}); |
@@ -10,3 +10,3 @@ 'use strict'; | ||
QUnit.module('can-globals/js/global'); | ||
QUnit.module('can-globals/global/global'); | ||
@@ -13,0 +13,0 @@ test('basics', function(){ |
@@ -6,3 +6,3 @@ 'use strict'; | ||
QUnit.module("can-util/js/is-browser-window"); | ||
QUnit.module("can-globals/is-browser-window/is-browser-window"); | ||
@@ -9,0 +9,0 @@ QUnit.test("basics", function(){ |
@@ -6,3 +6,3 @@ 'use strict'; | ||
unit.module('can-util/dom/location/location'); | ||
unit.module('can-globals/location/location'); | ||
@@ -9,0 +9,0 @@ unit.test('Can set a location', function (assert) { |
{ | ||
"name": "can-globals", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "This module provides a dependency injection container. Modules may define a key and specify a default value (which can be static, cached lazy, or dynamic lazy), but other code can set and reset the value as needed. There is also an event system, for alerting on value changes, both specific to a key and for any key.", | ||
@@ -5,0 +5,0 @@ "main": "can-globals.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34743
855