From 06d07e166b40621ce5db5edd288aaf35b3e8f5c6 Mon Sep 17 00:00:00 2001 From: Josh Perez Date: Mon, 6 Apr 2015 17:16:57 -0700 Subject: [PATCH] Allow you to generateActions in subclass --- dist/alt-browser-with-addons.js | 2 +- dist/alt-browser.js | 2 +- dist/alt-with-runtime.js | 2 +- dist/alt.js | 2 +- src/alt.js | 4 +++- test/index.js | 4 ++++ 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/dist/alt-browser-with-addons.js b/dist/alt-browser-with-addons.js index 24f47d69..659b69c6 100644 --- a/dist/alt-browser-with-addons.js +++ b/dist/alt-browser-with-addons.js @@ -1595,7 +1595,7 @@ var Alt = (function () { // Instance type methods for injecting alt into your application as context value: function addActions(name, ActionsClass) { - this.actions[name] = this.createActions(ActionsClass); + this.actions[name] = Array.isArray(ActionsClass) ? this.generateActions.apply(this, ActionsClass) : this.createActions(ActionsClass); } }, addStore: { diff --git a/dist/alt-browser.js b/dist/alt-browser.js index 66fcfd63..ba9aa55e 100644 --- a/dist/alt-browser.js +++ b/dist/alt-browser.js @@ -1339,7 +1339,7 @@ var Alt = (function () { // Instance type methods for injecting alt into your application as context value: function addActions(name, ActionsClass) { - this.actions[name] = this.createActions(ActionsClass); + this.actions[name] = Array.isArray(ActionsClass) ? this.generateActions.apply(this, ActionsClass) : this.createActions(ActionsClass); } }, addStore: { diff --git a/dist/alt-with-runtime.js b/dist/alt-with-runtime.js index 61efae6e..b9c7c726 100644 --- a/dist/alt-with-runtime.js +++ b/dist/alt-with-runtime.js @@ -588,7 +588,7 @@ var Alt = (function () { // Instance type methods for injecting alt into your application as context value: function addActions(name, ActionsClass) { - this.actions[name] = this.createActions(ActionsClass); + this.actions[name] = Array.isArray(ActionsClass) ? this.generateActions.apply(this, ActionsClass) : this.createActions(ActionsClass); } }, addStore: { diff --git a/dist/alt.js b/dist/alt.js index 229ffd57..447e88b8 100644 --- a/dist/alt.js +++ b/dist/alt.js @@ -606,7 +606,7 @@ var Alt = (function () { // Instance type methods for injecting alt into your application as context value: function addActions(name, ActionsClass) { - this.actions[name] = this.createActions(ActionsClass); + this.actions[name] = Array.isArray(ActionsClass) ? this.generateActions.apply(this, ActionsClass) : this.createActions(ActionsClass); } }, addStore: { diff --git a/src/alt.js b/src/alt.js index 8134297b..9637b34a 100644 --- a/src/alt.js +++ b/src/alt.js @@ -533,7 +533,9 @@ class Alt { // Instance type methods for injecting alt into your application as context addActions(name, ActionsClass) { - this.actions[name] = this.createActions(ActionsClass) + this.actions[name] = Array.isArray(ActionsClass) + ? this.generateActions.apply(this, ActionsClass) + : this.createActions(ActionsClass) } addStore(name, StoreModel, saveStore) { diff --git a/test/index.js b/test/index.js index 3ccd6ad2..b7679318 100644 --- a/test/index.js +++ b/test/index.js @@ -317,6 +317,7 @@ class AltInstance extends Alt { constructor() { super() this.addActions('myActions', MyActions) + this.addActions('fauxActions', ['one', 'two']) this.addStore('myStore', MyStore) } } @@ -762,6 +763,9 @@ const tests = { const myActionsFromInst = altInstance.getActions('myActions') assert.isObject(myActionsFromInst, 'the actions exist') + const fauxActions = altInstance.getActions('fauxActions') + assert.isFunction(fauxActions.one, 'faux actions were generated') + const myActionsFail = altInstance.getActions('ActionsThatDontExist') assert.isUndefined(myActionsFail, 'undefined actions')