Releases: canjs/can-observable-mixin
v1.0.8
Set default to null / undefined without type
This fixes setting property value to null
or undefined
, for example:
class Foo extends ObservableObject() {
static get props() {
return {
nullProp: { default: null },
undefinedProp: { default: undefined }
};
}
}
var foo = new Foo();
foo.nullProp // -> null
foo.undefinedProp // -> undefined
and
class Foo extends ObservableObject() {
static get props() {
return {
nullProp: null ,
undefinedProp: undefined
};
}
}
var foo = new Foo();
foo.nullProp // -> null
foo.undefinedProp // -> undefined
Test fix for CanJS build
This fixes the test for type errors in order to make CanJS test suite pass.
Catch type errors only
This catchs can-type
error to check the presence of .type
property in order to use it for message improvements.
Get update and updateDeep to work on list-like objects
This patch release fixes .update
and updateDeep
behavior when called on list-like objects.
The following code was throwing an exception due to both methods always calling canReflect.updateMap
and canReflect.updateDeepMap
under the hood even if the caller was an array.
class MyArray extends mixinMapProps(Array) {}
let arr = new MyArray();
arr.push(1, 2, 3, 4);
assert.equal(arr.length, 4);
arr.updateDeep([]); // throws an exception
assert.equal(arr.length, 0);
Enhance type error message
This enhance type error message by adding the value type in the message:
Before:
farah.age = '4'; // -> Uncaught Error: 4 is not of type Number. Property age is using "type: Number". Use "age: type.convert(Number)" to automatically convert values to Numbers when setting the "age" property.
`
Now:
farah.age = '4'; // -> Uncaught Error: "4" (string) is not of type Number. Property age is using "type: Number". Use "age: type.convert(Number)" to automatically convert values to Numbers when setting the "age" property.
Fix weirdness with arrays
list
property will have Array
type with an example like the following:
class Foo extends mixinObject() {
static get props() {
return {
list: []
};
}
}
var foo = new Foo();
foo.list = [ "one", "two" ];
TypeError: Right-hand side of 'instanceof'
error will not be thrown.
Type error message improvement
This improve the error message bu suggestion to use type.convert
for the right type:
class Person extends mixinObject() {
static get props() {
return {
age: type.check(Number)
};
}
}
var farah = new Person();
farah.age = '4'; // -> `Uncaught Error: 4 is not of type Number. Property age is using "type: Number". Use "age: type.convert(Number)" to automatically convert values to Numbers when setting the "age" property.`