mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
hasChanged shouldn't be true after the constructor.
This commit is contained in:
@@ -235,7 +235,6 @@
|
||||
var defaults;
|
||||
var attrs = attributes || {};
|
||||
this.cid = _.uniqueId('c');
|
||||
this.changed = {};
|
||||
this.attributes = {};
|
||||
if (options && options.collection) this.collection = options.collection;
|
||||
if (options && options.parse) attrs = this.parse(attrs, options) || {};
|
||||
@@ -243,6 +242,7 @@
|
||||
attrs = _.defaults({}, attrs, defaults);
|
||||
}
|
||||
this.set(attrs, options);
|
||||
this.changed = {};
|
||||
this.initialize.apply(this, arguments);
|
||||
};
|
||||
|
||||
@@ -354,7 +354,6 @@
|
||||
this.trigger('change', this, options);
|
||||
}
|
||||
}
|
||||
// this.changed = {};
|
||||
this._pending = false;
|
||||
this._changing = false;
|
||||
return this;
|
||||
|
||||
@@ -309,7 +309,7 @@ $(document).ready(function() {
|
||||
|
||||
test("change, hasChanged, changedAttributes, previous, previousAttributes", 9, function() {
|
||||
var model = new Backbone.Model({name: "Tim", age: 10});
|
||||
deepEqual(model.changedAttributes(), {name: "Tim", age: 10});
|
||||
deepEqual(model.changedAttributes(), false);
|
||||
model.on('change', function() {
|
||||
ok(model.hasChanged('name'), 'name changed');
|
||||
ok(!model.hasChanged('age'), 'age did not');
|
||||
@@ -317,15 +317,15 @@ $(document).ready(function() {
|
||||
equal(model.previous('name'), 'Tim');
|
||||
ok(_.isEqual(model.previousAttributes(), {name : "Tim", age : 10}), 'previousAttributes is correct');
|
||||
});
|
||||
equal(model.hasChanged(), true);
|
||||
equal(model.hasChanged(undefined), true);
|
||||
equal(model.hasChanged(), false);
|
||||
equal(model.hasChanged(undefined), false);
|
||||
model.set({name : 'Rob'});
|
||||
equal(model.get('name'), 'Rob');
|
||||
});
|
||||
|
||||
test("changedAttributes", 3, function() {
|
||||
var model = new Backbone.Model({a: 'a', b: 'b'});
|
||||
deepEqual(model.changedAttributes(), {a: 'a', b: 'b'});
|
||||
deepEqual(model.changedAttributes(), false);
|
||||
equal(model.changedAttributes({a: 'a'}), false);
|
||||
equal(model.changedAttributes({a: 'b'}).a, 'b');
|
||||
});
|
||||
@@ -610,6 +610,18 @@ $(document).ready(function() {
|
||||
equal(model.hasChanged('x'), true);
|
||||
});
|
||||
|
||||
test("hasChanged gets cleared on the following set", 4, function() {
|
||||
var model = new Backbone.Model;
|
||||
model.set({x: 1});
|
||||
ok(model.hasChanged());
|
||||
model.set({x: 1});
|
||||
ok(!model.hasChanged());
|
||||
model.set({x: 2});
|
||||
ok(model.hasChanged());
|
||||
model.set({});
|
||||
ok(!model.hasChanged());
|
||||
});
|
||||
|
||||
test("save with `wait` succeeds without `validate`", 1, function() {
|
||||
var model = new Backbone.Model();
|
||||
model.url = '/test';
|
||||
|
||||
Reference in New Issue
Block a user