Skip to content

Commit

Permalink
Register destructor for storage objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikek2252 committed Feb 6, 2024
1 parent 3248c5d commit aea53d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
7 changes: 5 additions & 2 deletions addon/adapters/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { get } from '@ember/object';
import BaseAdapter from './base';
import { getStorage, _buildKey } from '../helpers/storage';
import StorageArray from '../local/array';
import { getOwner } from '@ember/application';

export default BaseAdapter.extend({
_storage: getStorage('local'),
Expand All @@ -11,8 +12,10 @@ export default BaseAdapter.extend({

if (!indices[type]) {
let storageKey = _buildKey(this, 'index-' + type);

indices[type] = StorageArray.extend({ _storageKey: storageKey }).create();
let owner = getOwner(this);
indices[type] = StorageArray.extend({ _storageKey: storageKey }).create(
owner.ownerInjection()
);
}

return indices[type];
Expand Down
7 changes: 5 additions & 2 deletions addon/adapters/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { get } from '@ember/object';
import BaseAdapter from './base';
import { getStorage, _buildKey } from '../helpers/storage';
import StorageArray from '../session/array';
import { getOwner } from '@ember/application';

export default BaseAdapter.extend({
_storage: getStorage('session'),
Expand All @@ -11,8 +12,10 @@ export default BaseAdapter.extend({

if (!indices[type]) {
let storageKey = _buildKey(this, 'index-' + type);

indices[type] = StorageArray.extend({ _storageKey: storageKey }).create();
let owner = getOwner(this);
indices[type] = StorageArray.extend({ _storageKey: storageKey }).create(
owner.ownerInjection()
);
}

return indices[type];
Expand Down
8 changes: 7 additions & 1 deletion addon/mixins/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { set, get } from '@ember/object';
import { isArray, A } from '@ember/array';
import { getStorage } from '../helpers/storage';
import { copy } from 'ember-copy';
import { getOwner } from '@ember/application';
import { associateDestroyableChild } from '@ember/destroyable';

export default Mixin.create({
_storageKey: null,
Expand Down Expand Up @@ -41,7 +43,10 @@ export default Mixin.create({
// Keep in sync with other windows
this._addStorageListener();

return this._super(...arguments);
this._super(...arguments);

let owner = getOwner(this);
associateDestroyableChild(owner, this);
},

_getInitialContentCopy() {
Expand Down Expand Up @@ -86,6 +91,7 @@ export default Mixin.create({
},

_save() {
if (this.isDestroying || this.isDestroyed) return;
const storage = this._storage();
const content = get(this, 'content');
const storageKey = get(this, '_storageKey');
Expand Down

0 comments on commit aea53d6

Please sign in to comment.