diff --git a/lib/index.js b/lib/index.js index 5af32d7..473e7f4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -19,7 +19,7 @@ module.exports = function loopbackComponentFsm(app) { function getModelName(instance) { return instance.constructor.definition.name - } + } function generateCacheKey(instance) { if (!instance.id) { @@ -54,7 +54,9 @@ module.exports = function loopbackComponentFsm(app) { throw new Error(`${modelName} does not have state machine support.`) } - config = Object.assign(config, { initial: instance.status }) + let stateProperty = config.stateProperty; + + config = Object.assign(config, { initial: instance[stateProperty] }) cache = new StateMachine(config) debug('Created new state machine for instance %s with config %o', instance.id, config) diff --git a/lib/mixins/state-machine.js b/lib/mixins/state-machine.js index 16164f8..70d7f88 100644 --- a/lib/mixins/state-machine.js +++ b/lib/mixins/state-machine.js @@ -10,6 +10,7 @@ module.exports = function StateMachine(Model, settings) { // Initialize the main StateMachine config. Model.__FSM_CONFIG__ = { + stateProperty: stateProperty, events: settings.events, callbacks: { // When leaving any state, grab the initial model instance and set in options for eacy access. @@ -134,7 +135,7 @@ module.exports = function StateMachine(Model, settings) { const force = _.get(params, 'force') const origFrom = Model.__FSM_CONFIG__.events[eventNameIndex].from - const newFrom = [ ...origFrom, this.status ] + const newFrom = [ ...origFrom, this[stateProperty] ] // If force has been requested, override the state machine config. if (force && (forceFsmSetting || forceEventSetting)) {