-
Notifications
You must be signed in to change notification settings - Fork 28
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
Fluent interface #73
base: master
Are you sure you want to change the base?
Fluent interface #73
Conversation
So, I sketched out a first try with some tests ported from the original API. Amazingly enough I succeeded in making it even backwards compatible, i.e. we have 2 API's now: the "old" one and the fluent one. We need to ask ourselves whether we want to present users with two API's or one? And if the latter, which one? |
Ah yes, I didn't include commands yet. Since I didn't quite know how to call the mapping method. E.g. context.wire(FooCommand)
.toEvent("system:somethingHappened") Also, there's some technical difficulties, so I didn't want to start stirring that hornet's nest until I know what you think about the fluent API idea. |
I do love the legibility though: context.wire(clazz)
.asClass(key)
.withWiring({
foo : "foo"
})
.withContextEvents({
"event:foo" : "doSomething"
})
.withParameters(payload, a, b); |
After thinking some more about this I'd like to propose the following API: Level 1
Level 2
Level 3
If we want to maintain backwards compatibility we can simply replace the current methods with sugary ones: function wireSingleton(key, clazz, wiring){
this.wire(clazz).asSingleton(key).withWiring(wiring);
} Or release a separate |
Or we can go the full road: context.wire(Foo)
.as.singleton('foo')
.using.wiring(wiring)
.and.listeners(listenersMap)
.and.configuration(a,b,c); //edit: Nope, don't like this one. |
So, thinking about this some more, if we stick to the idea of having the methods reflect what is returned from the context, we really need to think about/rename:
The full explanation of On the other hand, maybe we should rethink the entire naming scheme. ATM it looks like the object that is |
Also, some food for thought: in SwiftSuspenders (which both the old API and the new API are based on) there's the notion of providers, i.e. a |
I'm starting to sway towards the idea of having a fluent interface. I didn't deem it necessary at first, but with
Context#configure
and a few of the new things I'd like to add, a FI seems to make sense.Something like:
The thing is, I notice I'm pulling more and more of the Geppetto stuff out of the ordinary actors and into the wiring phase, which means you need more possibilities, which in turn means you want to apply more methods to the same wiring configurations.
@geekdave what do you think?