ampersand-state
Advanced tools
Comparing version 4.4.1 to 4.4.2
@@ -548,3 +548,5 @@ /*$AMPERSAND_VERSION*/ | ||
} | ||
return _.result(def, 'default'); | ||
result = _.result(def, 'default'); | ||
this._values[name] = result; | ||
return result; | ||
} | ||
@@ -551,0 +553,0 @@ }); |
{ | ||
"name": "ampersand-state", | ||
"description": "An observable, extensible state object with derived watchable properties.", | ||
"version": "4.4.1", | ||
"version": "4.4.2", | ||
"author": "Henrik Joreteg <henrik@andyet.net>", | ||
@@ -6,0 +6,0 @@ "browserify": { |
@@ -188,3 +188,3 @@ # ampersand-state | ||
A special property of states, the **cid**, or a client id, is a unique identifier automatically assigned to all states when they are first created. Client ids are handy when the state has not been saved to the server, and so does not yet have it's true **id** but needs a unique id so it can be rendered in the UI etc. | ||
A special property of states, the **cid**, or a client id, is a unique identifier automatically assigned to all states when they are first created. Client ids are handy when the state has not been saved to the server, and so does not yet have its true **id** but needs a unique id so it can be rendered in the UI etc. | ||
@@ -260,3 +260,3 @@ ```javascript | ||
}catch(parseError){ | ||
// return the value with what we think it's type is | ||
// return the value with what we think its type is | ||
return { | ||
@@ -553,3 +553,3 @@ val : newVal, | ||
Shortcut to toggle boolean properties, or cycle through "ENUM" type properties that have a `values` array in it's definition. Fires change events as you would expect from set. | ||
Shortcut to toggle boolean properties, or cycle through "ENUM" type properties that have a `values` array in its definition. Fires change events as you would expect from set. | ||
@@ -556,0 +556,0 @@ ```javascript |
@@ -688,8 +688,21 @@ var tape = require('tape'); | ||
test('Values attribute default works', function (t) { | ||
test('Values attribute default works and is called only once', function (t) { | ||
var ran = 0; | ||
var Model = State.extend({ | ||
dataTypes: { | ||
countryType: { | ||
default: 'Atlantis' | ||
} | ||
}, | ||
props: { | ||
country: { | ||
type: 'countryType', | ||
required: true | ||
}, | ||
state: { | ||
values: ['CA', 'WA', 'NV'], | ||
default: 'CA' | ||
default: function(){ | ||
ran++; | ||
return 'CA'; | ||
} | ||
} | ||
@@ -700,5 +713,7 @@ } | ||
var m = new Model(); | ||
t.equal(m.state, 'CA', 'Should have applied the default'); | ||
t.equal(ran, 1, 'Should have been invoked only once'); | ||
t.equal(m.state, 'CA', 'Should have returned the same object'); | ||
t.equal(ran, 1, 'Should have been invoked only once'); | ||
t.equal(m.country, 'Atlantis'); | ||
t.throws(function () { | ||
@@ -710,2 +725,3 @@ m.state = 'PR'; | ||
test('toggle() works on boolean and values properties.', function (t) { | ||
@@ -712,0 +728,0 @@ var Model = State.extend({ |
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
120018
2925