Skip to content

Commit

Permalink
Merge pull request #57 from benkiefer/master
Browse files Browse the repository at this point in the history
switch the names of the properties on a record proxy to avoid collisi…
  • Loading branch information
toranb committed Jun 15, 2016
2 parents 6d4e488 + b6eac76 commit cfa03e6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 35 deletions.
6 changes: 3 additions & 3 deletions addon/models/filtered-record-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export default RecordArray.extend({
}),

updateContent() {
var source = this.get("source");
var filter_func = this.get("filter_func");
var source = this.get("_source");
var filter_func = this.get("_filter_func");

return Ember.A(source.filter(filter_func));
},
Expand All @@ -21,7 +21,7 @@ export default RecordArray.extend({
},

_unregisterRecordArray() {
var store = this.get("store");
var store = this.get("_store");
store._unsubscribe(this);
}
});
14 changes: 7 additions & 7 deletions addon/models/record-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ import Ember from 'ember';
const { ArrayProxy, computed } = Ember;

export default ArrayProxy.extend({
store: null,
type: null,
_store: null,
_type: null,

content: computed(function () {
return Ember.A(this.get("source"));
return Ember.A(this.get("_source"));
}),

push(data) {
var type = this.get('type');
return this.get('store').push(type, data);
var type = this.get('_type');
return this.get('_store').push(type, data);
},

remove(id) {
var type = this.get('type');
this.get('store').remove(type, id);
var type = this.get('_type');
this.get('_store').remove(type, id);
}
});
12 changes: 6 additions & 6 deletions addon/models/record-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import getOwner from 'ember-getowner-polyfill';
const { computed } = Ember;

export default Ember.ObjectProxy.extend({
source: null,
store: null,
type: null,
_source: null,
_store: null,
_type: null,

content: computed("source.[]", function() {
content: computed("_source.[]", function() {
return this.compute();
}),

init() {
this._super(...arguments);
const store = this.get('store');
const type = this.get('type');
const store = this.get('_store');
const type = this.get('_type');

var model = getOwner(store).lookup(`model:${type}`);

Expand Down
36 changes: 18 additions & 18 deletions addon/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ var Store = ServiceType.extend({
},
findOne(type) {
return RecordProxy.create({
store: this,
type: type,
source: this._findAll(type),
_store: this,
_type: type,
_source: this._findAll(type),
compute() {
return this.get("source").objectAt(0);
return this.get("_source").objectAt(0);
}
});
},
Expand All @@ -171,18 +171,18 @@ var Store = ServiceType.extend({
},
_findAllProxy(type) {
return RecordArray.create({
type: type,
store: this,
source: this._findAll(type)
_type: type,
_store: this,
_source: this._findAll(type)
});
},
_findWithFilterFunc(type, filter_func) {
var func = FilteredRecordArray.create({
type: type,
store: this,
id: Ember.uuid(),
filter_func: filter_func,
source: this._findAll(type)
_type: type,
_store: this,
_id: Ember.uuid(),
_filter_func: filter_func,
_source: this._findAll(type)
});
var filtersMap = this.get("filtersMap");
var filters = filtersMap[type] || [];
Expand All @@ -202,13 +202,13 @@ var Store = ServiceType.extend({
var primaryKey = primaryKeyForType(type, this);

return RecordProxy.create({
store: this,
type: type,
filter_value: actualId,
source: this._findAll(type),
_store: this,
_type: type,
_filter_value: actualId,
_source: this._findAll(type),
compute() {
var filter_value = this.get("filter_value");
return this.get("source").findBy(primaryKey, filter_value);
var filter_value = this.get("_filter_value");
return this.get("_source").findBy(primaryKey, filter_value);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/filters-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test('filters can be thrown out when you navigate away from a given route', func
});
});

test('filters on models with custom primary keys can be thrown out when you leave a route', function(assert) {
test('xxx filters on models with custom primary keys can be thrown out when you leave a route', function(assert) {
visit('/custom-key');
andThen(function() {
assert.equal(currentURL(), '/custom-key');
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,23 @@ test("find with filter should return array of models filtered by value", functio
assert.equal(store.find("person").get("length"), 5);
});

test("find with filter does not trump type property of object", function(assert) {
store.push("person", {
id: 9,
firstName: "Jarrod",
lastName: "Taylor",
source: "Jarrod's Mom",
store: "Walmart",
type: "developer"
});


var found = store.find("person", 9);
assert.equal(found.get("type"), "developer");
assert.equal(found.get("store"), "Walmart");
assert.equal(found.get("source"), "Jarrod's Mom");
});

test("find with filter should return array of models that tracks changes without asking for an update", function(assert) {
store.push("person", {
id: 9,
Expand Down

0 comments on commit cfa03e6

Please sign in to comment.