cujojs/wire — pull request #167 by protomouse (2014-12-06 17:09:16+00:00)
Title: bind factory: create partial function applications with injected arguments

This PR implements the `bind` factory, which takes a module that is a function/constructor and a list of arguments, and creates a component that is a partial application of that function on those arguments.

**Use case**
I'm using a third-party data format parser (`MapParser`) that supports binding constructors to annotated entities in the data. Whenever an bound entity is encountered, the parser instantiates an object by passing entity data to the corresponding constructor.

```js
function MapScreen(entityTypes) {
this.parser = new MapParser();
this.parser.bindTypes(entityTypes);
}

MapScreen.prototype.preload = function() {
this.map = this.parser.parse(this.assets.mapFile);
};
```

Here, `entityTypes` refers to an object injected by wire:

```js
mapScreen: {
create: {
module: 'screens/map_screen',
args: { $ref: 'entityTypes' }
}
},

entityTypes: {
opponent: {
bind: {
module: 'entities/opponent',
args: { $ref: 'opponentFactory' }
}
}
}
```

MapParser expects a unary constructor `function(entity)`, but the constructor requires additional components that must be wired in. Continuing the example above, `entities/opponent.js`:

```js
function Opponent(opponentFactory, entity) {
this.model = opponentFactory.create(entity.name);
}
```

In such scenarios, the `bind` factory can be useful.