From 94466c155f699a27c53064b115f063f4394a8f76 Mon Sep 17 00:00:00 2001 From: Robert-Frampton Date: Tue, 31 Oct 2017 08:39:39 -0700 Subject: [PATCH 1/3] Add failing test for issue #287 --- packages/metal-state/test/State.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/metal-state/test/State.js b/packages/metal-state/test/State.js index dbf8caf8..d5898904 100644 --- a/packages/metal-state/test/State.js +++ b/packages/metal-state/test/State.js @@ -1041,6 +1041,32 @@ describe('State', function() { assert.strictEqual('foo2', test2.key1); assert.strictEqual('foo1', test1.key1); }); + + it('should configure static STATE with multiple levels of class inheritance', function() { + var Test = createTestClass(); + Test.STATE = { + key1: { + } + }; + + class Child extends Test { + } + Child.STATE = { + key2: { + } + }; + + var test = new Test({ + key1: 'foo1' + }); + assert.strictEqual('foo1', test.key1); + + var child = new Child({ + key2: 'foo2' + }); + assert.strictEqual('foo1', test.key1); + assert.strictEqual('foo2', child.key2); + }); }); describe('Separate object', function() { From 9979b997dce6d072da60d6e1e01cc26a0007884d Mon Sep 17 00:00:00 2001 From: Robert-Frampton Date: Tue, 31 Oct 2017 08:59:53 -0700 Subject: [PATCH 2/3] Ensure that STATE configuration from static hints are properly configured with multiple levels of class inheritance --- packages/metal-state/src/State.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/metal-state/src/State.js b/packages/metal-state/src/State.js index 9340e2ae..6cffa471 100644 --- a/packages/metal-state/src/State.js +++ b/packages/metal-state/src/State.js @@ -280,8 +280,13 @@ class State extends EventEmitter { if (ctor !== State) { let defineContext; if (this.obj_ === this) { - defineContext = ctor.hasConfiguredState_ ? false : ctor.prototype; - ctor.hasConfiguredState_ = true; + const staticKey = State.STATE_STATIC_HINT_CONFIGURED; + + ctor[staticKey] = ctor[staticKey] || {}; + + defineContext = ctor[staticKey][ctor.name] ? false : + ctor.prototype; + ctor[staticKey][ctor.name] = true; } this.configState(State.getStateStatic(ctor), defineContext); } @@ -676,8 +681,20 @@ class State extends EventEmitter { } } +/** + * Constant used as key on State instance for storing property definition. + * @type {!string} + */ State.STATE_REF_KEY = '__METAL_STATE_REF_KEY__'; +/** + * Constant used as key on class constructors that extend form State, stores + * which constructors have had their static STATE configured so that + * configuration of STATE is not repeated. + * @type {!string} + */ +State.STATE_STATIC_HINT_CONFIGURED = '__METAL_STATE_STATIC_HINT_CONFIGURED__'; + /** * Constants that represent the states that a state key can be in. * @type {!Object} From 37c8a21390a8097b161d2d7041b928e2d47c5ef6 Mon Sep 17 00:00:00 2001 From: Robert-Frampton Date: Wed, 1 Nov 2017 11:28:05 -0700 Subject: [PATCH 3/3] Correct JSDocs --- packages/metal-state/src/State.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/metal-state/src/State.js b/packages/metal-state/src/State.js index 6cffa471..2d866082 100644 --- a/packages/metal-state/src/State.js +++ b/packages/metal-state/src/State.js @@ -271,8 +271,6 @@ class State extends EventEmitter { /** * Adds state keys from super classes static hint `MyClass.STATE = {};`. - * @param {Object.=} opt_config An object that maps all the - * configurations for state keys. * @protected */ configStateFromStaticHint_() { @@ -688,7 +686,7 @@ class State extends EventEmitter { State.STATE_REF_KEY = '__METAL_STATE_REF_KEY__'; /** - * Constant used as key on class constructors that extend form State, stores + * Constant used as key on class constructors that extend from State, stores * which constructors have had their static STATE configured so that * configuration of STATE is not repeated. * @type {!string}