Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename store and adapter #474

Merged
merged 1 commit into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions ember-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1419,9 +1419,9 @@ function getType(record) {
this.type = get(Ember.lookup, this.type);

if (!this.type) {
var store = record.container.lookup('store:main');
this.type = store.modelFor(type);
this.type.reopenClass({ adapter: store.adapterFor(type) });
var emstore = record.container.lookup('emstore:main');
this.type = emstore.modelFor(type);
this.type.reopenClass({ adapter: emstore.adapterFor(type) });
}
}

Expand Down Expand Up @@ -1481,7 +1481,7 @@ var get = Ember.get,

function storeFor(record) {
if (record.container) {
return record.container.lookup('store:main');
return record.container.lookup('emstore:main');
}

return null;
Expand All @@ -1494,9 +1494,9 @@ function getType(record) {
type = Ember.get(Ember.lookup, this.type);

if (!type) {
var store = storeFor(record);
type = store.modelFor(this.type);
type.reopenClass({ adapter: store.adapterFor(this.type) });
var emstore = storeFor(record);
type = emstore.modelFor(this.type);
type.reopenClass({ adapter: emstore.adapterFor(this.type) });
}
}

Expand Down Expand Up @@ -1524,8 +1524,8 @@ Ember.belongsTo = function(type, options) {
}
};

var store = storeFor(this),
value = this.getBelongsTo(key, type, meta, store);
var emstore = storeFor(this),
value = this.getBelongsTo(key, type, meta, emstore);
this._registerBelongsTo(meta);
if (value !== null && meta.options.embedded) {
value.get('isDirty'); // getter must be called before adding observer
Expand Down Expand Up @@ -1584,7 +1584,7 @@ Ember.belongsTo = function(type, options) {
};

Ember.Model.reopen({
getBelongsTo: function(key, type, meta, store) {
getBelongsTo: function(key, type, meta, emstore) {
var idOrAttrs = get(this, '_data.' + key),
record;

Expand All @@ -1598,8 +1598,8 @@ Ember.Model.reopen({
record = type.create({ isLoaded: false, id: id, container: this.container });
record.load(id, idOrAttrs);
} else {
if (store) {
record = store._findSync(meta.type, idOrAttrs);
if (emstore) {
record = emstore._findSync(meta.type, idOrAttrs);
} else {
record = type.find(idOrAttrs);
}
Expand Down Expand Up @@ -2037,11 +2037,11 @@ var DebugAdapter = Ember.DataAdapter.extend({

Ember.onLoad('Ember.Application', function(Application) {
Application.initializer({
name: "data-adapter",
name: "em-data-adapter",

initialize: function() {
var application = arguments[1] || arguments[0];
application.register('data-adapter:main', DebugAdapter);
application.register('em-data-adapter:main', DebugAdapter);
}
});
});
Expand Down Expand Up @@ -2112,16 +2112,16 @@ Ember.Model.Store = Ember.Object.extend({
Ember.onLoad('Ember.Application', function(Application) {

Application.initializer({
name: "store",
name: "emstore",

initialize: function() {
var application = arguments[1] || arguments[0];
var store = application.Store || Ember.Model.Store;
application.register('store:application', store);
application.register('store:main', store);
var emstore = application.Store || Ember.Model.Store;
application.register('emstore:application', emstore);
application.register('emstore:main', emstore);

application.inject('route', 'store', 'store:main');
application.inject('controller', 'store', 'store:main');
application.inject('route', 'emstore', 'emstore:main');
application.inject('controller', 'emstore', 'emstore:main');
}
});

Expand Down
18 changes: 9 additions & 9 deletions packages/ember-model/lib/belongs_to.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var get = Ember.get,

function storeFor(record) {
if (record.container) {
return record.container.lookup('store:main');
return record.container.lookup('emstore:main');
}

return null;
Expand All @@ -17,9 +17,9 @@ function getType(record) {
type = Ember.get(Ember.lookup, this.type);

if (!type) {
var store = storeFor(record);
type = store.modelFor(this.type);
type.reopenClass({ adapter: store.adapterFor(this.type) });
var emstore = storeFor(record);
type = emstore.modelFor(this.type);
type.reopenClass({ adapter: emstore.adapterFor(this.type) });
}
}

Expand Down Expand Up @@ -47,8 +47,8 @@ Ember.belongsTo = function(type, options) {
}
};

var store = storeFor(this),
value = this.getBelongsTo(key, type, meta, store);
var emstore = storeFor(this),
value = this.getBelongsTo(key, type, meta, emstore);
this._registerBelongsTo(meta);
if (value !== null && meta.options.embedded) {
value.get('isDirty'); // getter must be called before adding observer
Expand Down Expand Up @@ -107,7 +107,7 @@ Ember.belongsTo = function(type, options) {
};

Ember.Model.reopen({
getBelongsTo: function(key, type, meta, store) {
getBelongsTo: function(key, type, meta, emstore) {
var idOrAttrs = get(this, '_data.' + key),
record;

Expand All @@ -121,8 +121,8 @@ Ember.Model.reopen({
record = type.create({ isLoaded: false, id: id, container: this.container });
record.load(id, idOrAttrs);
} else {
if (store) {
record = store._findSync(meta.type, idOrAttrs);
if (emstore) {
record = emstore._findSync(meta.type, idOrAttrs);
} else {
record = type.find(idOrAttrs);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-model/lib/debug_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ var DebugAdapter = Ember.DataAdapter.extend({

Ember.onLoad('Ember.Application', function(Application) {
Application.initializer({
name: "data-adapter",
name: "em-data-adapter",

initialize: function() {
var application = arguments[1] || arguments[0];
application.register('data-adapter:main', DebugAdapter);
application.register('em-data-adapter:main', DebugAdapter);
}
});
});
6 changes: 3 additions & 3 deletions packages/ember-model/lib/has_many.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ function getType(record) {
this.type = get(Ember.lookup, this.type);

if (!this.type) {
var store = record.container.lookup('store:main');
this.type = store.modelFor(type);
this.type.reopenClass({ adapter: store.adapterFor(type) });
var emstore = record.container.lookup('emstore:main');
this.type = emstore.modelFor(type);
this.type.reopenClass({ adapter: emstore.adapterFor(type) });
}
}

Expand Down
10 changes: 5 additions & 5 deletions packages/ember-model/lib/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ Ember.Model.Store = Ember.Object.extend({
Ember.onLoad('Ember.Application', function(Application) {

Application.initializer({
name: "store",
name: "emstore",

initialize: function() {
var application = arguments[1] || arguments[0];
var store = application.Store || Ember.Model.Store;
application.register('store:application', store);
application.register('store:main', store);
application.register('emstore:application', store);
application.register('emstore:main', store);

application.inject('route', 'store', 'store:main');
application.inject('controller', 'store', 'store:main');
application.inject('route', 'emstore', 'emstore:main');
application.inject('controller', 'emstore', 'emstore:main');
}
});

Expand Down
8 changes: 4 additions & 4 deletions packages/ember-model/tests/store_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ QUnit.module("Ember.Model.Store", {
registry.register('model:test', TestModel);
registry.register('model:embedded', EmbeddedModel);
registry.register('model:uuid', UUIDModel);
registry.register('store:main', Ember.Model.Store);
registry.register('emstore:main', Ember.Model.Store);
}
});

Expand Down Expand Up @@ -224,11 +224,11 @@ QUnit.test("Registering a custom store on application works", function(assert) {
});

container = App.__container__;
assert.ok(container.lookup('store:application'));
assert.ok(container.lookup('store:main').get('custom'));
assert.ok(container.lookup('emstore:application'));
assert.ok(container.lookup('emstore:main').get('custom'));

var testRoute = container.lookup('route:test');
assert.ok(testRoute.get('store.custom'));
assert.ok(testRoute.get('emstore.custom'));

Ember.run(App, 'destroy');
});