notbenh / next.notbenh.info

I build a silly terminal as my webpage thinggie
1 stars 0 forks source link

better for the idea of action sets #19

Open notbenh opened 11 years ago

notbenh commented 11 years ago

Currently actions is just an object, though ideally if there is going to be a rampant idea of swapping action sets (see #1 for a great example) then there should be a better API for swapping and merging these sets.

The way that I am thinking of things is that there would be some 'default' action set ('help' for example) that would always be merged in to what ever set you have and this way you could do swaps like this:

t = new Terminal(...)
t.add_action('foo',function(){...},{GOAL:'bar'}) // add to t._instance_actions & merge .actions w/_instance_actions
var kitten = {pet : function(name){return 'you pet ' + name}}
t.swap_actions(kitten) // save kitten to t._kitten_action_set set t.actions = t._kitten_action_set && merge t._default_action_set
t.swap_actions() // defaults to instance effectively unrolling kitten 
t.swap_actions('kitten') // note string, does lookup to _kitten_action_set and does the swap
t.overwrite_actions(kitten) // same but do not merge _default_action_set