diff --git a/packages/metal-component/src/ComponentDataManager.js b/packages/metal-component/src/ComponentDataManager.js index 0bcb02b5..b5f09740 100644 --- a/packages/metal-component/src/ComponentDataManager.js +++ b/packages/metal-component/src/ComponentDataManager.js @@ -1,6 +1,6 @@ 'use strict'; -import {object} from 'metal'; +import {isDef, object} from 'metal'; import State from 'metal-state'; const BLACKLIST = { @@ -120,7 +120,7 @@ class ComponentDataManager { for (let i = 0; i < keys.length; i++) { const key = keys[i]; if (!state.getStateKeyConfig(key).internal) { - if (data.hasOwnProperty(key)) { + if (data.hasOwnProperty(key) && isDef(data[key])) { state.set(key, data[key]); } else { state.setDefaultValue(key); diff --git a/packages/metal-component/test/ComponentDataManager.js b/packages/metal-component/test/ComponentDataManager.js index 76cd03c9..7437d294 100644 --- a/packages/metal-component/test/ComponentDataManager.js +++ b/packages/metal-component/test/ComponentDataManager.js @@ -101,6 +101,27 @@ describe('ComponentDataManager', function() { assert.strictEqual('bar', component.bar); }); + it('should not favor undefined values over default values when replacing all non internal data', function() { + component.constructor.STATE = { + bar: { + value: 'initialBar', + }, + foo: { + value: 'initialFoo', + }, + }; + + initialConfig = {}; + ComponentDataManager.setUp(component, {}); + + ComponentDataManager.replaceNonInternal(component, { + bar: undefined, + foo: 'newFoo', + }); + assert.strictEqual('newFoo', component.foo); + assert.strictEqual('initialBar', component.bar); + }); + it('should return state instance', function() { ComponentDataManager.setUp(component, {}); assert.ok(