open-index/open-npm huggingface dataset:
npm package: @gigwalk/backbone-injector
Description: Small Backbone extension for injector.js dependency injection
Author: Paul Tondeur
Latest version: 0.1.5

# backbone-injector [![Build Status](https://travis-ci.org/biggerboat/backbone-injector.png)](https://travis-ci.org/biggerboat/backbone-injector)

Automatic dependency injection within all ```Backbone.View``` instances. This is build on top of [Backbone](https://github.com/jashkenas/backbone) and [injector.js](https://github.com/biggerboat/injector.js)

## Install
You could just download ```backbone-injector.js``` or ```backbone-injector.min.js``` from the project root.

We advise you to download it using [Bower](http://http://bower.io/) instead:
```
bower install backbone-injector
```
This command will automatically download all dependencies. So in this case it takes care of downloading 
[injector.js](https://github.com/biggerboat/injector.js), jQuery, Backbone and Underscore for you.

## Usage
To use the dependency injection, you need to pass an instance of the injector as the ```injector``` argument while instantiating a view.
This plugin will take care of the boilerplate and automatically injects the view before the ```initialize``` method is called.

See for example the following code stemming from a Jasmine test:
```JavaScript
var model = new Backbone.Model();
var injectorInstance = new injector.Injector();
injectorInstance.map('model').toValue(model);

var ViewClass = Backbone.View.extend({
	model: 'inject'
});

var view = new ViewClass({injector:injectorInstance});

expect(view.model).toEqual(model);
```

Under the hood the ```Backbone.View``` is adjusted prototype and make sure the dependency injection takes place before the ```initialize``` method is called.
Thus it is safe to rely on the view to be injected once you start using it.

We also inject the injector inside each view. This is for convenience, so you can easily pass it on to other view instances.
```JavaScript
var injectorInstance = new injector.Injector();
var view = new ViewClass({injector:injectorInstance});

expect(view.injector).toEqual(injectorInstance);
```

For example usage of this library, please refer to [Navigator-Injector-Backbone-Command-TodoMVC example](https://github.com/BiggerBoat/nibc-todomvc).

## Support
Feel free to create a [new issue](https://github.com/biggerboat/backbone-injector/issues/new) for all your questions, issues or feature requests.
npm package: @gigwalk/backbone-recursive-tojson
Description: Small Backbone extension for recursively calling toJSON on models and collections
Author: Paul Tondeur
Latest version: 0.1.3

# backbone-recursive-toJSON [![Build Status](https://travis-ci.org/biggerboat/backbone-recursive-toJSON.png)](https://travis-ci.org/biggerboat/backbone-recursive-toJSON)

*Note: Tracis-CI reports a failing build at the moment. Somehow there is a configuration issue with Travis. All tests are passing on many browsers I've tested with.*

This little helper alters the ```Backbone.Model.toJSON``` method. When this call is executed we loop through all the
properties and see if there is another object that has the ```toJSON``` method. If an array is detected we will loop over
all items and see if there is an object with a ```toJSON``` method.

This makes it easy to do:
```JavaScript
var modelA = new Backbone.Model({name:'modelA'});
var modelB = new Backbone.Model({name:'modelB'});
modelA.set({otherModel:modelB});

var modelAData = modelA.toJSON();

console.log(modelAData.otherModel.name);
```

Be aware for circular relationships, is this will get you in a recursive loop. So for example ```modelA``` having a reference to
```modelB``` and ```modelB``` having a reference back to ```modelA```.

Please see the specs for full details or consult [Navigator-Injector-Backbone-Command-TodoMVC example](https://github.com/BiggerBoat/nibc-todomvc) as an example on how this project could be used.

## Backbone.Relational
Make sure to check out [Backbone.Relational](https://github.com/PaulUithol/Backbone-relational) too. For me it turned out this was exactly what I was looking for.