Skip to content
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

new API and old composition #5

Closed
ghost opened this issue Aug 26, 2015 · 2 comments
Closed

new API and old composition #5

ghost opened this issue Aug 26, 2015 · 2 comments

Comments

@ghost
Copy link

ghost commented Aug 26, 2015

Perhaps I'm missing something obvious here, but by changing the api to "possum returns something you interact with" from a "possum is the final step" I've had to rethink how composition works:

old

var spec = {
  // possum object with states, handlers, etc.
}

return someDecorator(spec)

// some-decorator.js
function someDecorator(possumSpec) {
  return possum(possumSpec)
    .compose(decoratedBehavior)
    .compose(mixinBehaviors)
}

This makes it rather easy to create a highly-composed stamp that sits on top of the base possum implementation.

new

var model = someDecorator()
  .config({ ... })
  .states({ ... })

return model

// some-decorator.js
function someDecorator() {
  return possum()
    .compose(decoratedBehavior)
    .compose(mixinBehaviors)
    .compose(ohNoIBrokeMyOtherComposition)
}

This gives the implementation override possibility over the decoration because of the order of invocation on .compose() . It's different, and probably for the better, but still: I DONT LIKE CHANGE!

I suppose I could monkey patch the old functionality, but I don't like monkeys:

function someDecorator() {
  var model = possum()
  var builder = model.build
  model.build = function() {
    model
      .compose(decoratedBehavior)
      .compose(yayImSafeNoOneRodeOverMe)
    return builder()
  }
}

Thoughts?

@mnichols
Copy link
Owner

I don't understand your second sample since it isnt valid. But...
possum() returns a builder. If you use compose then it will delegate to the underlying api model and compose those behaviors in. When you call build it will have your compositions in there.
If you want access to the underlying apimodel without calling build you can call stamp() on the builder.
If you are managing state separately you will need to call target on the resulting stamp, but you have full access to compose how you like using that method.

@mnichols
Copy link
Owner

Ok I think I follow you now...you are asking to extend all possums using a compose call on the builder factory.
I'll see what I can do

@mnichols mnichols reopened this Aug 27, 2015
mnichols added a commit that referenced this issue Aug 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant