nickfargo/state — Issue #3: `child.state()` not providing all necessary delegator functions
Author: nickfargo
Created: 2012-01-26 16:09:02+00:00
State: open

For a class with a stateful prototype, if method `bar` is assigned per-instance, within the constructor, subsequent calls to `bar` don't get delegated to the local controller:

```coffeescript
class Foo
constructor: ->
@bar = -> 'bar'
@state()
state @::
Fizzy:
bar: -> 'barfz'
Buzzy:
bar: -> 'barbz'

foo = new Foo ; console.log foo.bar()
foo.state().change 'Fizzy' ; console.log foo.bar()
foo.state().change 'Buzzy' ; console.log foo.bar()

# output: bar bar bar
# expected: bar barfz barbz
```

Meanwhile `bar` behaves properly if assigned only to the prototype:

```coffeescript
class Foo
constructor: ->
@state()
bar: -> 'bar'
state @::
Fizzy:
bar: -> 'barfz'
Buzzy:
bar: -> 'barbz'

foo = new Foo ; console.log foo.bar()
foo.state().change 'Fizzy' ; console.log foo.bar()
foo.state().change 'Buzzy' ; console.log foo.bar()

# output: bar barfz barbz
# expected: bar barfz barbz
```

The call to `@state()` should iterate through all delegator functions held by all root protostates, and for any matching key found on the local instance whose value is a function, that function should be swapped with a delegator in the normal fashion.