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
namespace 'TimeLog.View', (exports) -> | |
class exports.Log extends Backbone.View | |
tagName: 'li' | |
events: | |
'click .date': 'lala' | |
template = _.template(""" |
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
test("multiple nested changes with silent2", 4, function() { | |
var changes = []; | |
var changesa = []; | |
var model = new Backbone.Model(); | |
model.on('change:b', function(model, val) { changes.push(val); }); | |
model.on('change:a', function(model, val) { changesa.push(val); }); | |
model.on('change', function() { | |
model.set({b:3}, {silent:true}); | |
model.set({a:3}, {silent:true}); | |
model.set({a:1}, {silent: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
// Returns a hash of attributes whose current and previous value differ. | |
_changed : function(){ | |
var attr, changes = {}, | |
now = this.attributes, | |
old = this._previousAttributes || {}; | |
var all = _.union(_.keys(now), _.keys(old)); | |
// If the new and current value differ, record the change. | |
for (var i = all.length; i>=0; i--) { |
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 case: | |
test("multiple nested changes with silent", 2, function() { | |
var changes = []; | |
var model = new Backbone.Model(); | |
model.on('change:b', function(model, val) { changes.push(val); }); | |
model.on('change', function() { | |
model.set({b: 1}); | |
model.set({b: 2}, {silent: 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
test("#1664 - silent changes on changing attributes triggered by other attributes", 1, function() { | |
var changes = []; | |
var model = new Backbone.Model({a:'a', b:1, c:'item'}); | |
model.on('change:a change:b change:c', function(model, val) { changes.push(val); }); | |
model.on('change', function() { | |
model.set({a:'c'}, {silent:true}); | |
}); | |
model.change(); | |
model.set({a:'a'}, {silent:true}); | |
model.change(); |
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
var YourModel = Backbone.Collection.extend({ | |
beforeDestroy:function () { | |
if (/*someLogic*/) { | |
this.destroy(); | |
} | |
}, | |
}) | |
var YourCollection = Backbone.Collection.extend({ | |
model: YourModel, |
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
var BaseModel = Backbone.Model.extend({ | |
destroy: function () { | |
if (!this.beforeDestroy || this.beforeDestroy() !== false) { | |
Backbone.Model.prototype.destroy.apply(this, arguments); | |
} | |
} | |
}); |
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
<script src="/socket.io/socket.io.js"></script> | |
<script src="/lib/q.js"></script> | |
<script> | |
var socket = io.connect('http://localhost'); | |
</script> | |
// ... | |
<script> | |
var model = new SocketModel(); |
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
var Book = Backbone.Model.extend(); | |
var book = new Book(); | |
book instanceof Book // true | |
book instanceof Backbone.Model // true | |
var Relation = function () {}; | |
Relation.extend = Backbone.Model.extend | |
var RelatedBook = Relation.extend(Book.prototype); | |
var relatedBook = new RelatedBook(); |
OlderNewer