Skip to content

Commit

Permalink
Merge pull request #103 from ampatspell/issue-101/storage-ref-metadat…
Browse files Browse the repository at this point in the history
…a-ref

Move storage.ref.metadata.reference to ref, deprecate reference
  • Loading branch information
ampatspell authored Aug 23, 2018
2 parents 7c50ce5 + 8e6e333 commit 2f58e9a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 5 additions & 1 deletion addon/-private/storage/reference/base/model.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EmberObject from '@ember/object';
import EmberObject, { computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';
import ModelMixin from '../../../internal/model-mixin';
import Mixin from '@ember/object/mixin';
Expand All @@ -12,6 +12,10 @@ const StatePropertiesMixin = Mixin.create(state.reduce((hash, key) => {

export default EmberObject.extend(ModelMixin, StatePropertiesMixin, {

ref: computed(function() {
return this._internal.ref.model(true);
}).readOnly(),

// { optional }
load: invokePromiseReturningThis('load')

Expand Down
9 changes: 5 additions & 4 deletions addon/-private/storage/reference/metadata/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Model from '../base/model';
import { state } from '../base/internal';
import serialized from '../../../util/serialized';
import { computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';
import { readOnly, deprecatingAlias } from '@ember/object/computed';
import { invokePromiseReturningThis } from '../../../internal/invoke';

const raw = () => computed('raw', function(key) {
Expand All @@ -23,9 +23,10 @@ const rawDate = key => computed('raw', function() {

export default Model.extend({

reference: computed(function() {
return this._internal.ref.model(true);
}).readOnly(),
reference: deprecatingAlias('ref', {
id: 'ember-cli-zuglet-store-reference-metadata-ref',
until: '0.9.0'
}),

raw: readOnly('_internal._metadata'),

Expand Down
8 changes: 7 additions & 1 deletion tests/unit/storage-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ module('storage', function(hooks) {
let metadata = ref.get('metadata');
assert.ok(metadata);
assert.ok(metadata._internal);
assert.ok(metadata.get('reference') === ref);
assert.ok(metadata.get('reference') === ref); // deprecated
assert.ok(metadata.get('ref') === ref);

assert.deepEqual(metadata.get('serialized'), {
"error": null,
Expand Down Expand Up @@ -535,6 +536,11 @@ module('storage', function(hooks) {
assert.equal(images.get('fullPath'), 'images');
});

test('url has ref', async function(assert) {
let ref = this.storage.ref({ path: 'hello' });
assert.ok(ref.get('url.ref') === ref);
});

test('load url', async function(assert) {
await this.signIn();
await this._put();
Expand Down

0 comments on commit 2f58e9a

Please sign in to comment.