Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
2,024 additions
and
732 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'} | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
})); | ||
``` |
Oops, something went wrong.