cujojs / wire

A light, fast, flexible Javascript IOC container
Other
861 stars 68 forks source link

Context builder API #100

Open briancavalier opened 11 years ago

briancavalier commented 11 years ago

Imagine an API like:

function wire(contextBuilder: function) : Promise;

Where contextBuilder is a function that receives some new API that can be used to programmatically build up a wired context (or more likely a promise for one):

function myContextBuilder(someNewWireAPI) {
    // Call various methods on someNewWireAPI to create and configure components
    return <some opaque representation of the context built up by someNewWireAPI>;
}

This quite powerful. The current object literal parser could even be built from such an API:

function objectLiteralParserContextBuilder(someNewWireAPI) {
    // parse object literal as we do today and call methods on someNewWireAPI
    return <some opaque representation of the context built up by someNewWireAPI>;
}

Parsers for other formats could be built in the same way, or someone could simply choose to use the programmatic API if they prefer that style.

The object literal parser is currently too entangled in the machinery to make this work in the short term, but I really think this could be a good direction to go after 0.10.0.

Thoughts?

scothis commented 11 years ago

Decoupling the object-literal spec format from the wire machinery can only be a good thing. Do you have a feel for the impact on plugin authors? Or if this change would make sense before 1.0 vs 2.0?

unscriptable commented 11 years ago

+1. seems like a worthwhile endeavor