You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 20, 2022. It is now read-only.
Denormalizes an input based on schema and provided entities from a plain object or Immutable data. The reverse of `normalize`.
47
47
48
-
*Special Note:* Be careful with denormalization. Prematurely reverting your data to large, nested objects could cause performance impacts in React (and other) applications.
48
+
_Special Note:_ Be careful with denormalization. Prematurely reverting your data to large, nested objects could cause performance impacts in React (and other) applications.
49
49
50
50
If your schema and data have recursive references, only the first instance of an entity will be given. Subsequent references will be returned as the `id` provided.
51
51
52
-
*`input`: **required** The normalized result that should be *de-normalized*. Usually the same value that was given in the `result` key of the output of `normalize`.
52
+
*`input`: **required** The normalized result that should be _de-normalized_. Usually the same value that was given in the `result` key of the output of `normalize`.
53
53
*`schema`: **required** A schema definition that was used to get the value for `input`.
54
54
*`entities`: **required** An object, keyed by entity schema names that may appear in the denormalized output. Also accepts an object with Immutable data.
55
55
@@ -59,36 +59,32 @@ If your schema and data have recursive references, only the first instance of an
Creates a schema to normalize an array of entities. If the input value is an `Object` instead of an `Array`, the normalized result will be an `Array` of the `Object`'s values.
79
+
Creates a schema to normalize an array of entities. If the input value is an `Object` instead of an `Array`, the normalized result will be an `Array` of the `Object`'s values.
83
80
84
-
*Note: The same behavior can be defined with shorthand syntax: `[ mySchema ]`*
81
+
_Note: The same behavior can be defined with shorthand syntax: `[ mySchema ]`_
85
82
86
-
*`definition`: **required** A singular schema that this array contains *or* a mapping of schema to attribute values.
87
-
*`schemaAttribute`: *optional* (required if `definition` is not a singular schema) The attribute on each entity found that defines what schema, per the definition mapping, to use when normalizing.
88
-
Can be a string or a function. If given a function, accepts the following arguments:
89
-
* `value`: The input value of the entity.
90
-
* `parent`: The parent object of the input array.
91
-
* `key`: The key at which the input array appears on the parent object.
83
+
*`definition`: **required** A singular schema that this array contains _or_ a mapping of schema to attribute values.
84
+
*`schemaAttribute`: _optional_ (required if `definition` is not a singular schema) The attribute on each entity found that defines what schema, per the definition mapping, to use when normalizing.
85
+
Can be a string or a function. If given a function, accepts the following arguments:
86
+
_ `value`: The input value of the entity.
87
+
_ `parent`: The parent object of the input array. \*`key`: The key at which the input array appears on the parent object.
92
88
93
89
#### Instance Methods
94
90
@@ -99,12 +95,12 @@ Can be a string or a function. If given a function, accepts the following argume
99
95
To describe a simple array of a singular entity type:
If your input data is an array of more than one type of entity, it is necessary to define a schema mapping.
122
+
If your input data is an array of more than one type of entity, it is necessary to define a schema mapping.
127
123
128
-
*Note: If your data returns an object that you did not provide a mapping for, the original object will be returned in the result and an entity will not be created.*
124
+
_Note: If your data returns an object that you did not provide a mapping for, the original object will be returned in the result and an entity will not be created._
*`key`: **required** The key name under which all entities of this type will be listed in the normalized response. Must be a string name.
161
+
*`key`: **required** The key name under which all entities of this type will be listed in the normalized response. Must be a string name or [Symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol).
163
162
*`definition`: A definition of the nested entities found within this entity. Defaults to empty object.
164
-
You *do not* need to define any keys in your entity other than those that hold nested entities. All other values will be copied to the normalized entity's output.
163
+
You _do not_ need to define any keys in your entity other than those that hold nested entities. All other values will be copied to the normalized entity's output.
165
164
*`options`:
166
-
-`idAttribute`: The attribute where unique IDs for each of this entity type can be found.
165
+
*`idAttribute`: The attribute where unique IDs for each of this entity type can be found.
167
166
Accepts either a string `key` or a function that returns the IDs `value`. Defaults to `'id'`.
168
-
As a function, accepts the following arguments, in order:
169
-
*`value`: The input value of the entity.
170
-
*`parent`: The parent object of the input array.
171
-
*`key`: The key at which the input array appears on the parent object.
172
-
-`mergeStrategy(entityA, entityB)`: Strategy to use when merging two entities with the same `id` value. Defaults to merge the more recently found entity onto the previous.
173
-
-`processStrategy(value, parent, key)`: Strategy to use when pre-processing the entity. Use this method to add extra data, defaults, and/or completely change the entity before normalization is complete. Defaults to returning a shallow copy of the input entity.
174
-
*Note: It is recommended to always return a copy of your input and not modify the original.*
175
-
The function accepts the following arguments, in order:
176
-
*`value`: The input value of the entity.
177
-
*`parent`: The parent object of the input array.
178
-
*`key`: The key at which the input array appears on the parent object.
167
+
As a function, accepts the following arguments, in order:
168
+
*`value`: The input value of the entity.
169
+
*`parent`: The parent object of the input array.
170
+
*`key`: The key at which the input array appears on the parent object.
171
+
*`mergeStrategy(entityA, entityB)`: Strategy to use when merging two entities with the same `id` value. Defaults to merge the more recently found entity onto the previous.
172
+
*`processStrategy(value, parent, key)`: Strategy to use when pre-processing the entity. Use this method to add extra data, defaults, and/or completely change the entity before normalization is complete. Defaults to returning a shallow copy of the input entity.
173
+
_Note: It is recommended to always return a copy of your input and not modify the original._
174
+
The function accepts the following arguments, in order:
175
+
*`value`: The input value of the entity.
176
+
*`parent`: The parent object of the input array.
177
+
*`key`: The key at which the input array appears on the parent object.
179
178
180
179
#### Instance Methods
181
180
@@ -192,7 +191,10 @@ You *do not* need to define any keys in your entity other than those that hold n
Define a plain object mapping that has values needing to be normalized into Entities. *Note: The same behavior can be defined with shorthand syntax: `{ ... }`*
258
+
Define a plain object mapping that has values needing to be normalized into Entities. _Note: The same behavior can be defined with shorthand syntax: `{ ... }`_
260
259
261
260
*`definition`: **required** A definition of the nested entities found within this object. Defaults to empty object.
262
-
You *do not* need to define any keys in your object other than those that hold other entities. All other values will be copied to the normalized output.
261
+
You _do not_ need to define any keys in your object other than those that hold other entities. All other values will be copied to the normalized output.
263
262
264
263
#### Instance Methods
265
264
@@ -269,7 +268,7 @@ You *do not* need to define any keys in your object other than those that hold o
@@ -296,7 +295,7 @@ Describe a schema which is a union of multiple schemas. This is useful if you ne
296
295
297
296
*`definition`: **required** An object mapping the definition of the nested entities found within the input array
298
297
*`schemaAttribute`: **required** The attribute on each entity found that defines what schema, per the definition mapping, to use when normalizing.
299
-
Can be a string or a function. If given a function, accepts the following arguments:
298
+
Can be a string or a function. If given a function, accepts the following arguments:
300
299
*`value`: The input value of the entity.
301
300
*`parent`: The parent object of the input array.
302
301
*`key`: The key at which the input array appears on the parent object.
@@ -307,17 +306,20 @@ Can be a string or a function. If given a function, accepts the following argume
307
306
308
307
#### Usage
309
308
310
-
*Note: If your data returns an object that you did not provide a mapping for, the original object will be returned in the result and an entity will not be created.*
309
+
_Note: If your data returns an object that you did not provide a mapping for, the original object will be returned in the result and an entity will not be created._
Describes a map whose values follow the given schema.
339
341
340
-
*`definition`: **required** A singular schema that this array contains *or* a mapping of schema to attribute values.
341
-
*`schemaAttribute`: *optional* (required if `definition` is not a singular schema) The attribute on each entity found that defines what schema, per the definition mapping, to use when normalizing.
342
-
Can be a string or a function. If given a function, accepts the following arguments:
342
+
*`definition`: **required** A singular schema that this array contains _or_ a mapping of schema to attribute values.
343
+
*`schemaAttribute`: _optional_ (required if `definition` is not a singular schema) The attribute on each entity found that defines what schema, per the definition mapping, to use when normalizing.
344
+
Can be a string or a function. If given a function, accepts the following arguments:
343
345
*`value`: The input value of the entity.
344
346
*`parent`: The parent object of the input array.
345
347
*`key`: The key at which the input array appears on the parent object.
If your input data is an object that has values of more than one type of entity, but their schema is not easily defined by the key, you can use a mapping of schema, much like `schema.Union` and `schema.Array`.
374
376
375
-
*Note: If your data returns an object that you did not provide a mapping for, the original object will be returned in the result and an entity will not be created.*
377
+
_Note: If your data returns an object that you did not provide a mapping for, the original object will be returned in the result and an entity will not be created._
0 commit comments