Skip to content

Commit

Permalink
Update to give warning if value is set to a constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
bgando committed Aug 31, 2017
1 parent 21787bb commit 3bf43ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions can-define.js
Expand Up @@ -239,9 +239,9 @@ define.property = function(objPrototype, prop, definition, dataInitializers, com
if ((definition.value !== undefined || definition.Value !== undefined)) {
//!steal-remove-start

// If value is an object or array, give a warning
if (definition.value !== null && typeof definition.value === 'object') {
dev.warn("can-define: The value for options is set to an object. This will be shared by all instances of the DefineMap. Use a function that returns the object instead.");
// If value is an object, array, or constructor give a warning
if (definition.value !== null && (typeof definition.value === 'object' || canReflect.isConstructorLike(definition.value || {}))) {
dev.warn("can-define: The value for " + prop + " is set to an object or constructor. Use a function or primitive instead.");
}
//!steal-remove-end
getInitialValue = Observation.ignore(make.get.defaultValue(prop, definition, typeConvert, eventsSetter));
Expand Down
6 changes: 3 additions & 3 deletions map/map-test.js
Expand Up @@ -839,11 +839,11 @@ QUnit.test("non-Object constructor", function() {
});

if(System.env.indexOf("production") < 0) {
QUnit.test('Setting a value with an object type generates a warning (#148)', function() {
QUnit.test('Setting a value with an object or constructor type generates a warning (#148)', function() {
QUnit.expect(2);
var oldwarn = canDev.warn;
canDev.warn = function(mesg) {
QUnit.equal(mesg, "can-define: The value for options is set to an object. This will be shared by all instances of the DefineMap. Use a function that returns the object instead.");
QUnit.equal(mesg, "can-define: The value for options is set to an object or constructor. Use a function or primitive instead.");
};
//should issue a warning
DefineMap.extend({
Expand All @@ -854,7 +854,7 @@ if(System.env.indexOf("production") < 0) {
//should issue a warning
DefineMap.extend({
options: {
value: []
value: DefineMap
}
});

Expand Down

0 comments on commit 3bf43ab

Please sign in to comment.