GeppettoJS / backbone.geppetto

Bring your Backbone applications to life with an event-driven Command framework.
http://geppettojs.github.com/backbone.geppetto/
MIT License
203 stars 28 forks source link

Proposed API #32

Closed creynders closed 10 years ago

creynders commented 11 years ago

API proposition for Backbone.Geppetto:

Based on #22, #24 and #28

  1. createChildResolver() <- Injector#createChildInjector
  2. getObject(key) unchanged
  3. wireValue(key, value) <- Injector#mapValue
  4. hasWiring(key) <- Injector#hasMapping
  5. wireClass(key, clazz) <- Injector#mapClass
  6. wireView(key, clazz) <- Injector#mapView
  7. wireSingleton(key, clazz) <- Injector#mapSingleton
  8. instantiate(key) unchanged
  9. resolve(instance) <- Injector#injectInto
  10. release(key) <- Injector#unmap
  11. releaseAll(key) <- Injector#unmapAll
  12. bindContext(options) unchanged
  13. on(event, callback, [scope]) <- Context#listen (Backbone.Events)
  14. once(event, callback, [scope]) new (Backbone.Events)
  15. off([event], [callback], [scope]) new (Backbone.Events)
  16. listenTo(other, event, callback) <- Context#listen (Backbone.Events)
  17. listenToOnce(other, event, callback) new (Backbone.Events)
  18. stopListening([other], [event], [callback]) new (Backbone.Events)
  19. trigger(event, [...args]) <- Context#dispatch (Backbone.Events)
  20. triggerOnParent(event, [...args]) <- Context#dispatchToParent
  21. triggerGlobally(event, [...args]) <- Context#dispatchGlobally
  22. wireCommand(event, commandClass) <- Context#mapCommand
  23. wireCommands(wirings) <- Context#mapCommands
  24. destroy() <- Context#unmapAll

And as an optional parameter to Context#initialize:

wires:{ //or maybe 'wirings' ?
    commands: {
        "appEventFoo":          FooCommand,
        "appEventFooBarBaz":    [
            FooCommand,
            BarCommand,
            BazCommand
        ]
    },
    singletons: {
        foo: Foo
    },
    classes :{
        bar: Bar
    },
    values : {
        someValue: 10
    },
    views: {
        qux : Qux
    }
}

So, what do you think?

geekdave commented 11 years ago

Definitely like the idea of setting up the mappings in external files and pulling them into the Context. Otherwise the Context file could definitely grow into an unwieldy beast. Let's track this separately as https://github.com/ModelN/backbone.geppetto/issues/35

creynders commented 11 years ago

Any more thoughts on this? The current project I'm working on could really benefit from DI, it'd be nice to get this pushed through. I'll gladly do all necessary changes, but need an idea on which changes you guys want. Shall I leave the messaging as is and just prepare everything concerning DI?

geekdave commented 11 years ago

I'm on vacation at the moment and our team design review is not until the end of the month so that is the soonest that we could finalize any changes. Unfortunately we need to be a bit more slow moving on this since we have built two large enterprise apps on Geppetto and need to find time in our project cycle when everyone has time to review the changes and the impact on existing code.

That being said I do expect the DI stuff to be supported so I think you can move forward with your DI related changes. I'll keep you updated as things progress.

On Sunday, September 15, 2013, creynders wrote:

Any more thoughts on this? The current project I'm working on could really benefit from DI, it'd be nice to get this pushed through. I'll gladly do all necessary changes, but need an idea on which changes you guys want. Shall I leave the messaging as is and just prepare everything concerning DI?

— Reply to this email directly or view it on GitHubhttps://github.com/ModelN/backbone.geppetto/issues/32#issuecomment-24466282 .

creynders commented 11 years ago

Bunch of changes pushed:

  1. all map methods renamed to wire
  2. dependers can register their dependencies using an object (was Array only till now)
  3. switchboard object to wire methods as discussed in #33
  4. Context wraps most of Resolver (=previously Injector) methods
  5. Context#wireCommands refactored and made public
flashape commented 10 years ago

Awesome work! What's the status with this? Is that api above ready for use?

geekdave commented 10 years ago

@flashape : Working on finalizing and documenting the API in the next week or so. Sorry for the delays. Not everything above has been implemented yet, but the heart of the DI APIs are now working.

We have been using the new APIs in production at my company and I don't foresee any major changes from what's currently in master. So if you're ready to roll with the new DI stuff, and you can get by without the docs for now, you can safely go ahead.

I'll send out an email to the Geppetto Google Group when the docs are done.

geekdave commented 10 years ago

The API above has been fully implemented*. Huge thanks to @creynders for putting the work into enumerating these methods. I'll be using this list to update the README soon.

*the one exception is that we decided not to rename dispatch to trigger. We can revisit this in a separate issue later on, but for now we did not see the need.