Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
igorT committed Nov 5, 2019
1 parent b21d9d0 commit a71c2db
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 84 deletions.
80 changes: 0 additions & 80 deletions packages/store/addon/-private/system/core-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3595,86 +3595,6 @@ function _commit(adapter, store, operation, snapshot) {
);
}

/**
*
* @param store
* @param cache modelFactoryCache
* @param normalizedModelName already normalized modelName
* @return {*}
*/
function getModelFactory(store, cache, normalizedModelName) {
let factory = cache[normalizedModelName];

if (!factory) {
factory = _lookupModelFactory(store, normalizedModelName);

if (!factory) {
//Support looking up mixins as base types for polymorphic relationships
factory = _modelForMixin(store, normalizedModelName);
}

if (!factory) {
// we don't cache misses in case someone wants to register a missing model
return null;
}

let klass = factory.class;
assert(`'${inspect(klass)}' does not appear to be an ember-data model`, klass.isModel);

// TODO: deprecate this
let hasOwnModelNameSet = klass.modelName && klass.hasOwnProperty('modelName');
if (!hasOwnModelNameSet) {
klass.modelName = normalizedModelName;
}

cache[normalizedModelName] = factory;
}

return factory;
}

function _lookupModelFactory(store, normalizedModelName) {
let owner = getOwner(store);

return owner.factoryFor(`model:${normalizedModelName}`);
}

/*
In case someone defined a relationship to a mixin, for example:
```
import Model, { belongsTo, hasMany } from '@ember-data/model';
let Comment = Model.extend({
owner: belongsTo('commentable'. { polymorphic: true })
});
let Commentable = Ember.Mixin.create({
comments: hasMany('comment')
});
```
we want to look up a Commentable class which has all the necessary
relationship metadata. Thus, we look up the mixin and create a mock
Model, so we can access the relationship CPs of the mixin (`comments`)
in this case
*/
function _modelForMixin(store, normalizedModelName) {
let owner = getOwner(store);
let MaybeMixin = owner.factoryFor(`mixin:${normalizedModelName}`);
let mixin = MaybeMixin && MaybeMixin.class;

if (mixin) {
let ModelForMixin = Model.extend(mixin);
ModelForMixin.reopenClass({
__isMixin: true,
__mixin: mixin,
});

//Cache the class as a model
owner.register('model:' + normalizedModelName, ModelForMixin);
}

return _lookupModelFactory(store, normalizedModelName);
}

let assertDestroyingStore: Function;
let assertDestroyedStoreOnly: Function;

Expand Down
4 changes: 1 addition & 3 deletions packages/store/addon/-private/system/model/internal-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import RSVP, { Promise } from 'rsvp';
import Ember from 'ember';
import { DEBUG } from '@glimmer/env';
import { assert, inspect } from '@ember/debug';
import { deprecate } from '@ember/application/deprecations';
import Model from './model';
import RootState from './states';
import Snapshot from '../snapshot';
import OrderedSet from '../ordered-set';
import ManyArray from '../many-array';
import { PromiseBelongsTo, PromiseManyArray } from '../promise-proxies';
import Store from '../ds-model-store';
import { errorsHashToArray, errorsArrayToHash } from '../errors-utils';
import { errorsHashToArray } from '../errors-utils';

import { RecordReference, BelongsToReference, HasManyReference } from '../references';
import { default as recordDataFor, relationshipStateFor } from '../record-data-for';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Store from '../ds-model-store';
import InternalModel from '../model/internal-model';
import recordDataFor from '../record-data-for';
import { Object as JSONObject, Value as JSONValue } from 'json-typescript';
Expand Down

0 comments on commit a71c2db

Please sign in to comment.