@ember-data/store 4.12.0-beta.8 → 4.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,7 +19,8 @@
19
19
 
20
20
  This package provides [*Ember***Data**](https://github.com/emberjs/data/)'s `Store` class.
21
21
 
22
- The `Store` coordinates interaction between your application, the `Cache`, and sources of data (such as your `API` or a local persistence layer).
22
+ The `Store` coordinates interaction between your application, a [Cache](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Cache),
23
+ and sources of data (such as your API or a local persistence layer) accessed via a [RequestManager](https://github.com/emberjs/data/tree/main/packages/request).
23
24
 
24
25
  ```mermaid
25
26
  flowchart LR
@@ -57,15 +58,15 @@ After installing you will want to configure your first `Store`. Read more below
57
58
 
58
59
  ## 🔨 Creating A Store
59
60
 
60
- To use a `Store` we will need to do few things: add a `Cache` to store data **in-memory**, add an `Adapter` to fetch data from a source, and implement `instantiateRecord` to tell the store how to display the data for individual resources.
61
+ To use a `Store` we will need to do few things: add a [Cache](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Cache) to store data **in-memory**, add a [Handler](https://github.com/emberjs/data/tree/main/packages/request#handling-requests) to fetch data from a source, and implement `instantiateRecord` to tell the store how to display the data for individual resources.
61
62
 
62
63
  > **Note** If you are using the package `ember-data` then a `JSON:API` cache and `instantiateRecord` are configured for you by default.
63
64
 
64
65
  ### Configuring A Cache
65
66
 
66
- To start, let's install a `JSON:API` cache. If your app uses `GraphQL` or `REST` other caches may better fit your data. You can author your own cache by creating one that conforms to the [spec]().
67
+ To start, let's install a [JSON:API](https://jsonapi.org/) cache. If your app uses `GraphQL` or `REST` other caches may better fit your data. You can author your own cache by creating one that conforms to the [spec](https://api.emberjs.com/ember-data/release/classes/%3CInterface%3E%20Cache).
67
68
 
68
- The package `@ember-data/json-api` provides a `JSON:API` cache we can use. After installing it, we can configure the store to use this cache.
69
+ The package [@ember-data/json-api](https://github.com/emberjs/data/tree/main/packages/json-api) provides a [JSON:API](https://jsonapi.org/) cache we can use. After installing it, we can configure the store to use this cache.
69
70
 
70
71
  ```js
71
72
  import Store from '@ember-data/store';
@@ -80,9 +81,7 @@ class extends Store {
80
81
 
81
82
  Now that we have a `cache` let's setup something to handle fetching and saving data via our API.
82
83
 
83
- > **Note** [1] the cache from `@ember-data/json-api` is a special cache: if the package is present the `createCache` hook will automatically do the above wiring if the hook is not implemented. We still recommend implementing the hook.
84
- >
85
- > **Note** [2] The `ember-data` package automatically includes the `@ember-data/json-api` cache for you.
84
+ > **Note** The `ember-data` package automatically includes and configures the `@ember-data/json-api` cache for you.
86
85
 
87
86
  ### Handling Requests
88
87
 
@@ -93,7 +92,7 @@ To start, let's install the `FetchManager` from `@ember-data/request` and the ba
93
92
  > **Note** If your app uses `GraphQL`, `REST` or different conventions for `JSON:API` than your cache expects, other handlers may better fit your data. You can author your own handler by creating one that conforms to the [handler interface](https://github.com/emberjs/data/tree/main/packages/request#handling-requests).
94
93
 
95
94
  ```ts
96
- import Store from '@ember-data/store';
95
+ import Store, { CacheHandler } from '@ember-data/store';
97
96
  import RequestManager from '@ember-data/request';
98
97
  import Fetch from '@ember-data/request/fetch';
99
98
 
@@ -102,6 +101,7 @@ export default class extends Store {
102
101
  super(...arguments);
103
102
  this.requestManager = new RequestManager();
104
103
  this.requestManager.use([Fetch]);
104
+ this.requestManager.useCache(CacheHandler);
105
105
  }
106
106
  }
107
107
  ```
@@ -113,12 +113,14 @@ Alternatively if you have configured the `RequestManager` to be a service you ma
113
113
  *app/services/request.js*
114
114
  ```ts
115
115
  import RequestManager from '@ember-data/request';
116
+ import { CacheHandler } from '@ember-data/store';
116
117
  import Fetch from '@ember-data/request/fetch';
117
118
 
118
119
  export default class extends RequestManager {
119
120
  constructor(createArgs) {
120
121
  super(createArgs);
121
122
  this.use([Fetch]);
123
+ this.useCache(CacheHandler);
122
124
  }
123
125
  }
124
126
  ```
@@ -135,7 +137,8 @@ export default class extends Store {
135
137
 
136
138
  ### Presenting Data from the Cache
137
139
 
138
- Now that we have a source and a cach for our data, we need to configure how the Store delivers that data back to our application. We do this via the hook `instantiateRecord`, which allows us to transform the data for a resource before handing it to the application.
140
+ Now that we have a source and a cach for our data, we need to configure how the Store delivers that data back to our application. We do this via the hook [instantiateRecord](https://api.emberjs.com/ember-data/release/classes/Store/methods/instantiateRecord%20(hook)?anchor=instantiateRecord%20(hook)),
141
+ which allows us to transform the data for a resource before handing it to the application.
139
142
 
140
143
  A naive way to present the data would be to return it as JSON. Typically instead this hook will be used to add reactivity and make each unique resource a singleton, ensuring that if the cache updates our presented data will reflect the new state.
141
144
 
@@ -182,6 +185,5 @@ Typically you will choose an existing record implementation such as `@ember-data
182
185
 
183
186
  Because of the boundaries around instantiation and the cache, record implementations should be capable of interop both with each other and with any `Cache`. Due to this, if needed an application can utilize multiple record implementations and multiple cache implementations either to support enhanced features for only a subset of records or to be able to incrementally migrate from one record/cache to another record or cache.
184
187
 
185
- > Note: [1] `@ember-data/model` is a special record implementation: currently, if the package is present the `instantiateRecord` hook will automatically do the above wiring if the hook is not implemented.
186
- >
187
- > Note: [2] The `ember-data` package automatically includes the `@ember-data/model` implementation for you.
188
+ > **Note:** The `ember-data` package automatically includes the `@ember-data/model`
189
+ > package and configures it for you.
package/addon/-private.js CHANGED
@@ -1 +1 @@
1
- export { f as AdapterPopulatedRecordArray, C as CacheHandler, j as IDENTIFIER_ARRAY_TAG, I as IdentifierArray, M as MUTATE, I as RecordArray, R as RecordArrayManager, h as SOURCE, S as Store, _ as _clearCaches, e as coerceId, k as fastPush, i as isStableIdentifier, n as normalizeModelName, g as notifyArray, p as peekCache, r as recordIdentifierFor, l as removeRecordDataFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, s as storeFor } from "./index-0d52354f";
1
+ export { f as AdapterPopulatedRecordArray, C as CacheHandler, j as IDENTIFIER_ARRAY_TAG, I as IdentifierArray, M as MUTATE, I as RecordArray, R as RecordArrayManager, h as SOURCE, S as Store, _ as _clearCaches, e as coerceId, k as fastPush, i as isStableIdentifier, n as normalizeModelName, g as notifyArray, p as peekCache, r as recordIdentifierFor, l as removeRecordDataFor, c as setIdentifierForgetMethod, a as setIdentifierGenerationMethod, d as setIdentifierResetMethod, b as setIdentifierUpdateMethod, s as storeFor } from "./index-8b77b852";