-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ability to move states in other coffee scripts #13
Comments
The So in this regard I would say the user has full control on where/how is stuff defined. I'd imagine splitting the states (and helper functions) in separate file, where each file will return part of the plugins = []
# collect plugins -- each returns an object with {states: {}, helpers: {}} properties
states = {}
helpers = {}
for plugin in plugins
_.extend(states, plugin.states)
_.extend(helpers, plugin.helpers)
class StateMachine extend NodeState
states: states
constructor: ->
super
# whatever
# other global helper methods here
_.extend(StateMachine.prototype, helpers)
# now you can use StateMachine
sm = new StateMachine
|
Hi Iskren, Thanks for quick reply. Would you be kind enough to also show us how a plugin file will look like? I am novice in js/coffeescript and just getting started. Appreciate your help and quick reply. Thanks, Vinod From: Iskren Ivov Chernev [mailto:[email protected]] The states property is an object. So you can put different pieces of it in different files, then merge them together in the main file. Also you can add methods to the state machine (not states - just regular methods), after the fact (modifying the StateMachine.prototype (if you state machine is called StateMachine)). So in this regard I would say the user has full control on where/how is stuff defined. I'd imagine splitting the states (and helper functions) in separate file, where each file will return part of the states object (some keys), and part of the prototype (helper methods). Then the main file just iterates over all plugins and merges the states and prototype objects and creates an object with all of those: plugins = [] collect plugins -- each returns an object with {states: {}, helpers: {}} propertiesstates = {} class StateMachine extend NodeState constructor: -> other global helper methods here_.extend(StateMachine.prototype, helpers) now you can use StateMachinesm = new StateMachine _.extend just copies all properties from the second object to the first object. — |
So you should be using coffee-script with node.js I guess: Directory structure should be something like: where
Then inside the plugin file you say: # state_machine/first.coffee
exports.states =
A:
Enter: ->
@helperA()
B:
Enter: ->
exports.helpers =
helperA: -> And the main file would be # state_machine.coffee
plugins = [
require('state_machine/first')
require('state_machine/second')
]
# continue using plugins as in my first example You might want to add |
Iskren, Thanks a lot for your help. I have sent you a linked in request. Let me know if you are interested in moving to San Francisco Bay Area for full time opportunity. We would be glad to talk to you about some of openings in our company. You can read more about my company at www.efi.com http://www.efi.com Thanks, Vinod From: Iskren Ivov Chernev [mailto:[email protected]] So you should be using coffee-script with node.js I guess: Directory structure should be something like: where first and second are two plugins. . Then inside the plugin file you say: state_machine/first.coffeeexports.states = exports.helpers = And the main file would be state_machine.coffeeplugins = [ continue using plugins as in my first exampleYou might want to add transitions to the picture -- another property of each file, that gets merged the same way as states and then gets added to the object same as states. — |
Hi there, We have a very big statemachine in our use case and wondering if its possible to have individual states being exported into separate files. Can you please provide suggestions?
Thanks,Vinod
The text was updated successfully, but these errors were encountered: