Skip to content

Commit

Permalink
Merge 448e251 into d497fc7
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Jan 3, 2015
2 parents d497fc7 + 448e251 commit 8837014
Show file tree
Hide file tree
Showing 34 changed files with 2,024 additions and 732 deletions.
47 changes: 14 additions & 33 deletions .jshintrc
@@ -1,45 +1,26 @@
{
"node": true,
"browser": true,
"esnext": true,
"bitwise": true,
"camelcase": false,
"browser": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"expr": true,
"esnext": true,
"exported": ["attempt"],
"globals": {
"Backbone": true,
"Minionette": true,
"_": true,
"attempt": true
},
"immed": true,
"indent": 4,
"jquery": true,
"latedef": true,
"newcap": true,
"noarg": true,
"regexp": true,
"undef": true,
"unused": true,
"node": true,
"strict": false,
"trailing": true,
"smarttabs": true,
"jquery": true,
"white": false,
"globals": {
"jQuery": true,
"Backbone": true,
"_": true,
"Minionette": true,
"attempt": true,
"slice": true,
"define": true,
"sinon": true,
"chai": true,
"sinonChai": true,
"jqueryChai": true,
"describe": true,
"before": true,
"beforeEach": true,
"after": true,
"afterEach": true,
"expect": true,
"it": true
},
"exported": ["attempt"]
"undef": true,
"unused": true
}
9 changes: 7 additions & 2 deletions .travis.yml
Expand Up @@ -3,7 +3,12 @@ node_js:
- "0.11"
- "0.10"
before_script:
- npm install -g grunt-cli bower
- npm install -g bower coveralls codeclimate-test-reporter
- bower install --config.interactive=false
script:
- gulp test --coverage
after_success:
- grunt coverage
- coveralls < coverage/lcov.info
- codeclimate < coverage/lcov.info
env:
- secure: "DJ5P4TnXa6GL7GIZoZP2FAsHy6ivL9IPFJ08F3Z2B0nJ3DwM7D+3PeKgZOo0BwuV/H3enVlcRrfwCBdL00cbfna75JxFh8T8HeKRzYuOk7lQZUphHgftgyWuGHkIz7R4sAAYK7sbw2KRIIAVAjkxXjBhq1vG95S48RWpxr9DJO0="
96 changes: 0 additions & 96 deletions Gruntfile.js

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
Minionette [![Build Status](https://travis-ci.org/jridgewell/minionette.png?branch=master)](https://travis-ci.org/jridgewell/minionette) [![Code Climate](https://codeclimate.com/github/jridgewell/minionette.png)](https://codeclimate.com/github/jridgewell/minionette) [![Coverage Status](https://coveralls.io/repos/jridgewell/minionette/badge.png)](https://coveralls.io/r/jridgewell/minionette)
Minionette [![Build Status](https://travis-ci.org/jridgewell/minionette.svg?branch=master)](https://travis-ci.org/jridgewell/minionette) [![Code Climate](https://codeclimate.com/github/jridgewell/minionette.png)](https://codeclimate.com/github/jridgewell/minionette) [![Coverage Status](https://coveralls.io/repos/jridgewell/minionette/badge.png)](https://coveralls.io/r/jridgewell/minionette)
==========

A mini Marionette for Backbone.js
Expand Down
11 changes: 4 additions & 7 deletions bower.json
Expand Up @@ -14,15 +14,12 @@
"name": "Justin Ridgewell"
},
"dependencies": {
"backbone": "^1.0",
"jquery": ">=1.7.0",
"backbone": "~1.0",
"underscore": ">=1.4.4 <2.0"
"underscore": "^1.4.4"
},
"devDependencies": {
"mocha": "~1.12.0",
"chai": "~1.7.2",
"sinon": "~1.7.3",
"sinon-chai": "~2.4.0",
"chai-jquery": "~1.1.1"
"sinon-chai": "^2.4",
"chai-jquery": "^1.2"
}
}
2 changes: 1 addition & 1 deletion docs/minionette.collectionview.md
Expand Up @@ -38,7 +38,7 @@ var CV = Minionette.CollectionView.extend({
## #collectionEvents

```javascript
collectionEvents = {
CollectionView.prototype.collectionEvents = {
add: 'addOne',
remove: 'removeOne',
reset: 'render',
Expand Down
46 changes: 46 additions & 0 deletions docs/minionette.computed.md
@@ -0,0 +1,46 @@
Minionette.Computed
===================

`Minionette.Computed` is a helper function, designed to specify the
attributes a Model's method depends on for its result. When used in
conjunction with [Minionette.Model](/docs/minionette.model.md), any time
a dependent attribute changes, the computing function will be called.
Its return value is then set onto the model's attributes, using the same
name as the method.

```javascript
var Model = Minionette.Model.extend({
defaults: {
first: 'Jeremy',
last: 'Ashkenas'
},

initialize: function() {
console.log(this.attributes);
},

name: Minionette.Computed('first', 'last', function() {
return this.get('first') + ' ' + this.get('last');
})
});

var m = new Model();
// Computed attributes are set before #initialize
// Console: { first: 'Jeremy', last: 'Ashkenas', name: 'Jeremy Ashkenas' }

m.name(); // => 'Jeremy Ashkenas'
m.attributes // => { first: 'Jeremy', last: 'Ashkenas', name: 'Jeremy Ashkenas'}


m.set({ first: 'Test' });

m.name(); // => 'Test Ashkenas'
m.attributes // => { first: 'Test', last: 'Ashkenas', name: 'Test Ashkenas'}


m.set({ first: 'Backbone', last: 'Underscore' });

m.name(); // => 'Backbone Underscore'
m.attributes // => { first: 'Backbone', last: 'Underscore', name: 'Backbone Underscore'}

```
62 changes: 62 additions & 0 deletions docs/minionette.model.md
@@ -0,0 +1,62 @@
Minionette.Model
================

`Minionette.Model` is a base Model class, designed to work with
[Minionette.Computed](/docs/minionette.model.md). Any methods wrapped
inside a `Computed` will be called whenever a change event for the any
of the method's model dependencies happen. The computing method's return
value will be set to the attribute of the same name.

```javascript
var Dev = Minionette.Model.extend({
defaults: {
first: 'Jeremy',
last: 'Ashkenas'
},

initialize: function() {
console.log('Called #initialize');
console.log(this.attributes);
},

name: Minionette.Computed('first', 'last', function() {
console.log('Called #name');
return this.get('first') + ' ' + this.get('last');
})
});

var d = new Dev();
// Computed attributes are set before #initialize
// Console: Called #name
// Console: Called #initialize
// Console: { first: 'Jeremy', last: 'Ashkenas', name: 'Jeremy Ashkenas' }

d.set({ first: 'Test' });
// Console: Called #name
d.attributes // => { first: 'Test', last: 'Ashkenas', name: 'Test Ashkenas'}


d.set({ first: 'Backbone', last: 'Underscore' });
// Console: Called #name
// Console: Called #name
d.attributes // => { first: 'Backbone', last: 'Underscore', name: 'Backbone Underscore'}

d.trigger('change:first');
// Console: Called #name

```

## #toJSON()

By default, `Model`'s `#toJSON()` will omit any computed attributes.
There are two reasons for this behavior:

1. To save bandwidth when syncing with the server. Computed attributes
should also be computed on the server, meaning sending them is
unnecessary.
2. To discourage the use of `#toJSON()` when rendering a template.

```javascript
var d = new Dev();
d.toJSON(); // => { first: 'Jeremy', last: 'Ashkenas' }
```
2 changes: 1 addition & 1 deletion docs/minionette.modelview.md
Expand Up @@ -8,7 +8,7 @@ in, `#modelEvents` and `#serialize()`.
## #modelEvents

```javascript
modelEvents = {
ModelView.prototype.modelEvents = {
change: 'render',
destroy: 'remove'
};
Expand Down
70 changes: 70 additions & 0 deletions docs/minionette.router.md
@@ -0,0 +1,70 @@
Minionette.Router
=================

`Minionette.Router` is a base Router class, designed to separate your
app's routes from its controller actions. This prevents Router bloat by
moving the methods that handle each route to the controller.

```javascript
var postsController = {
index: function() {
console.log('Posts:', [1, 2, 3]);
},
show: function(id) {
console.log('Post:', id);
}
};
var usersController = {
login: function() {
//...
}
};

var Router = Minionette.Router.extend({

// Add any controllers you need
users: usersController,
posts: postsController,

routes: {
// Standard routes are welcome
'': 'index'

// Post's routes
'posts': 'posts/index',
'posts/:id': 'posts/show',

// User's routes
'users/login': 'users/login'
'users/posts/:id': 'posts/show'
},

index: function() {
console.log('Hompage');
}
});
```

## #routeToControllerAction(controller, action, args = [])

`Router`'s `#routeToControllerAction()` is used internally to call the
correct method on the correct controller. It is called whenever a
route's name matches the `{controller}/{method}` pattern, and receives
all parameter parts, splat parts, and the query string as `args`.
Override this method if you need any custom routing logic, eg. parsing
the query string parameters.

```javascript
var router = new (Minionette.Router.extend({
routes: {
'posts': 'posts/index'
},

routeToControllerAction: function(controller, action, args) {
var query = parseQuery(_.last(args));
args[args.length - 1] = query;

super(controller, action, args);
}
}));
```

0 comments on commit 8837014

Please sign in to comment.