Skip to content

Commit

Permalink
Merge pull request #371 from funkensturm/store-reopen
Browse files Browse the repository at this point in the history
Deprecate import-export mixin
  • Loading branch information
fsmanuel authored May 14, 2023
2 parents a4cff01 + a0c7d32 commit 338ceee
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 42 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,16 @@ jobs:
- ember-lts-4
- ember-lts-4.4
- ember-lts-4.8
- ember-4.9
- ember-4.10
- ember-4.11
- ember-lts-4.12
- ember-release
- ember-beta
- ember-canary
- ember-default-with-jquery
- embroider-safe
- embroider-optimized
# - embroider-optimized

steps:
- uses: actions/checkout@v3
Expand Down
60 changes: 40 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ You can use `queryRecord` to return only one record. See the [guides](https://gu
#### Export & Import
The addon ships with an initializer that enables export and import of you LocalStorage data.
The addon ships with utility functions that enables export and import of you LocalStorage data.
You have to add `fileExport` option to the `environment.js`:
```javascript
Expand All @@ -400,13 +400,34 @@ module.exports = function() {
};
```
The initializer provides `exportData()` and `importData()` on the store. Both return a Promise.
Import `exportData()` and `importData()` from `ember-local-storage/helpers/import-export`.
Both return a Promise.
```javascript
import Route from '@ember/routing/route';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { importData, exportData } from 'ember-local-storage/helpers/import-export';

export default class IndexRoute extends Route {
@service store;

@action
exportData() {
exportData(
this.store,
['posts', 'comments'],
{ download: true, filename: 'my-data.json' }
);
}

@action
importData(event) {
this.readFile(event.target.files[0]).then((file) => {
importData(this.store, file.data);
});
}

readFile(file) {
const reader = new FileReader();

Expand All @@ -423,34 +444,20 @@ export default class IndexRoute extends Route {
reader.readAsText(file);
});
}

@action
importData(event) {
this.readFile(event.target.files[0])
.then((file) => {
this.store.importData(file.data);
});
}

@action
exportData() {
this.store.exportData(
['posts', 'comments'],
{ download: true, filename: 'my-data.json' }
);
}
}
```
**importData(content, options)**
**importData(store, content, options)**
`store` the ember data store
`content` can be a JSON API compliant object or a JSON string
`options` are:
- `json` Boolean (default `true`)
- `truncate` Boolean (default `true`) if `true` the existing data gets replaced.
**exportData(types, options)**
**exportData(store, types, options)**
`store` the ember data store
`types` Array of types to export. The types must be pluralized.
Expand Down Expand Up @@ -525,6 +532,19 @@ module('basic acceptance test', function(hooks) {
## Deprecations
### mixins.adapters.import-export
until: 3.0.0
id: ember-local-storage.mixins.adapters.import-export
Using the import-export mixin has been deprecated and will be removed in version 3.0.0. You should use the utility functions provided by the addon:
```javascript
import { importData, exportData } from 'ember-local-storage/helpers/import-export';
```
See the [Export & Import example](#export--import).
### storageFor - legacyKey
until: 2.0.0
Expand Down
18 changes: 15 additions & 3 deletions addon/adapters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import { run } from '@ember/runloop';
import { isEmpty, typeOf } from '@ember/utils';
import { computed, get } from '@ember/object';
import JSONAPIAdapter from '@ember-data/adapter/json-api';
import ImportExportMixin from '../mixins/adapters/import-export';
import { _buildKey } from '../helpers/storage';
import {
importData,
exportData,
} from 'ember-local-storage/helpers/import-export';
import { _buildKey } from 'ember-local-storage/helpers/storage';

const getKeys = Object.keys || keys;

// Ember data ships with ember-inflector
import { singularize, pluralize } from 'ember-inflector';

export default JSONAPIAdapter.extend(ImportExportMixin, {
export default JSONAPIAdapter.extend({
_debug: false,
_indices: computed(function () {
return {};
Expand Down Expand Up @@ -41,6 +44,15 @@ export default JSONAPIAdapter.extend(ImportExportMixin, {
return Math.random().toString(32).slice(2).substr(0, 8);
},

// Import & Export
importData(store, content, options) {
return importData(store, content, options);
},

exportData(store, types, options) {
return exportData(store, types, options);
},

// Relationship sugar
createRecord(store, type, snapshot) {
snapshot.eachRelationship(function (name, relationship) {
Expand Down
19 changes: 19 additions & 0 deletions addon/mixins/adapters/import-export.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { deprecate } from '@ember/debug';
import Mixin from '@ember/object/mixin';
import {
importData,
Expand All @@ -6,10 +7,28 @@ import {

export default Mixin.create({
importData(store, content, options) {
deprecate(
'Using the import-export mixin has been deprecated and will be removed in version 3.0.0',
false,
{
id: 'ember-local-storage.mixins.adapters.import-export',
until: '3.0.0',
url: 'https://github.com/funkensturm/ember-local-storage#deprecations',
}
);
return importData(store, content, options);
},

exportData(store, types, options) {
deprecate(
'Using the import-export mixin has been deprecated and will be removed in version 3.0.0',
false,
{
id: 'ember-local-storage.mixins.adapters.import-export',
until: '3.0.0',
url: 'https://github.com/funkensturm/ember-local-storage#deprecations',
}
);
return exportData(store, types, options);
},
});
66 changes: 48 additions & 18 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ module.exports = async function () {
name: 'ember-lts-4',
npm: {
devDependencies: {
'@ember-data/adapter': '~4.0.0',
'@ember-data/debug': '~4.0.0',
'@ember-data/model': '~4.0.0',
'@ember-data/record-data': '~4.0.0',
'@ember-data/serializer': '~4.0.0',
'@ember-data/store': '~4.0.0',
'ember-auto-import': '^2.2.0',
'ember-data': '~4.0.0',
'ember-source': '~4.0.0',
Expand All @@ -64,12 +58,6 @@ module.exports = async function () {
name: 'ember-lts-4.4',
npm: {
devDependencies: {
'@ember-data/adapter': '~4.4.0',
'@ember-data/debug': '~4.4.0',
'@ember-data/model': '~4.4.0',
'@ember-data/record-data': '~4.4.0',
'@ember-data/serializer': '~4.4.0',
'@ember-data/store': '~4.4.0',
'ember-auto-import': '^2.2.0',
'ember-data': '~4.4.0',
'ember-source': '~4.4.0',
Expand All @@ -81,19 +69,57 @@ module.exports = async function () {
name: 'ember-lts-4.8',
npm: {
devDependencies: {
'@ember-data/adapter': '~4.8.0',
'@ember-data/debug': '~4.8.0',
'@ember-data/model': '~4.8.0',
'@ember-data/record-data': '~4.8.0',
'@ember-data/serializer': '~4.8.0',
'@ember-data/store': '~4.8.0',
'ember-auto-import': '^2.2.0',
'ember-data': '~4.8.0',
'ember-source': '~4.8.0',
webpack: '^5.0.0',
},
},
},
{
name: 'ember-4.9',
npm: {
devDependencies: {
'ember-auto-import': '^2.2.0',
'ember-data': '~4.9.0',
'ember-source': '~4.9.0',
webpack: '^5.0.0',
},
},
},
{
name: 'ember-4.10',
npm: {
devDependencies: {
'ember-auto-import': '^2.2.0',
'ember-data': '~4.10.0',
'ember-source': '~4.10.0',
webpack: '^5.0.0',
},
},
},
{
name: 'ember-4.11',
npm: {
devDependencies: {
'ember-auto-import': '^2.2.0',
'ember-data': '~4.11.0',
'ember-source': '~4.11.0',
webpack: '^5.0.0',
},
},
},
{
name: 'ember-lts-4.12',
npm: {
devDependencies: {
'ember-auto-import': '^2.2.0',
'ember-data': '~4.12.0',
'ember-source': '~4.12.0',
webpack: '^5.0.0',
},
},
},
{
name: 'ember-release',
npm: {
Expand All @@ -112,6 +138,8 @@ module.exports = async function () {
'ember-auto-import': '^2.2.0',
'ember-data': 'beta',
'ember-source': await getChannelURL('beta'),
'ember-resolver': '10.0.0',
'@ember/string': '3.0.1',
webpack: '^5.0.0',
},
},
Expand All @@ -123,6 +151,8 @@ module.exports = async function () {
'ember-auto-import': '^2.2.0',
'ember-data': 'canary',
'ember-source': await getChannelURL('canary'),
'ember-resolver': '10.0.0',
'@ember/string': '3.0.1',
webpack: '^5.0.0',
},
},
Expand Down

0 comments on commit 338ceee

Please sign in to comment.