Skip to content

Commit fb09f17

Browse files
committed
Standardize normalize vs normalise
1 parent 69cf98b commit fb09f17

File tree

9 files changed

+35
-35
lines changed

9 files changed

+35
-35
lines changed

packages/normy-react-query/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
<!-- [![Known Vulnerabilities](https://snyk.io/test/github/klis87/normy/badge.svg)](https://snyk.io/test/github/klis87/normy) -->
1212

13-
`react-query` integration with `normy` - automatic normalisation and data updates for data fetching libraries
13+
`react-query` integration with `normy` - automatic normalization and data updates for data fetching libraries
1414

1515
## Table of content
1616

1717
- [Introduction](#introduction-arrow_up)
1818
- [Motivation](#motivation-arrow_up)
1919
- [Installation](#installation-arrow_up)
2020
- [Basic usage](#basic-usage-arrow_up)
21-
- [Disabling of normalisation per query and mutation](#disabling-of-normalisation-per-query-and-mutation-arrow_up)
21+
- [Disabling of normalization per query and mutation](#disabling-of-normalization-per-query-and-mutation-arrow_up)
2222
- [Optimistic updates](#optimistic-updates-arrow_up)
2323
- [Garbage collection](#garbage-collection-arrow_up)
2424
- [Clearing and unsubscribing from updates](#clearing-and-unsubscribing-from-updates-arrow_up)
@@ -144,15 +144,15 @@ most of the time anymore.
144144
`createQueryNormalizer` accepts two arguments:
145145

146146
- `queryClient` - this is just a react-query instance you create by `new QueryClient(config)`,
147-
- `normalizerConfig` - this is `normy` config, which you might need to meet requirements for data normalisation to work - see
147+
- `normalizerConfig` - this is `normy` config, which you might need to meet requirements for data normalization to work - see
148148
[explanation](https://github.com/klis87/normy/tree/master/#required-conditions-arrow_up) for more details. Additionally to `normy` config, you can also pass `normalize` option, which is `true` by default - if you pass `false`, nothing will be normalized unless explicitely set (see the next paragraph)
149149

150-
## Disabling of normalisation per query and mutation [:arrow_up:](#table-of-content)
150+
## Disabling of normalization per query and mutation [:arrow_up:](#table-of-content)
151151

152152
By default all your queries and mutations will be normalized. That means that for each query there will be normalized representation
153153
of its data and for each mutation its response data will be read and all dependent normalized queries will be updated.
154154

155-
However, it does not always make sense to normalize all data. You might want to disable data normalisation, for example for performance reason for some extreme big queries,
155+
However, it does not always make sense to normalize all data. You might want to disable data normalization, for example for performance reason for some extreme big queries,
156156
or just if you do not need it for a given query, for instance if a query data will be never updated.
157157

158158
Anyway, you might want to change this globally by passing `normalize` to `createQueryNormalizer`:
@@ -216,8 +216,8 @@ The above code will immediately update all queries which have object with `id: 1
216216
a mutation error, data will be reverted to original `rollbackData`.
217217

218218
It will work at the same time as a normal mutation too, so on mutation success, all dependent queries will be updated
219-
again. If you are sure about the response structure, you might want to disable normalisation for this mutation,
220-
so that on successful response the normalisation won't be repeted unnecessarily:
219+
again. If you are sure about the response structure, you might want to disable normalization for this mutation,
220+
so that on successful response the normalization won't be repeted unnecessarily:
221221

222222
```jsx
223223
useMutation({

packages/normy-react-query/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@normy/react-query",
33
"version": "0.7.0",
4-
"description": "react-query addon for normy - Automatic normalisation and data updates for data fetching libraries",
4+
"description": "react-query addon for normy - Automatic normalization and data updates for data fetching libraries",
55
"main": "lib/index.js",
66
"module": "es/index.js",
77
"jsnext:main": "es/index.js",
@@ -11,7 +11,7 @@
1111
"license": "MIT",
1212
"typings": "types/index.d.ts",
1313
"keywords": [
14-
"normalisation",
14+
"normalization",
1515
"react-query"
1616
],
1717
"homepage": "https://github.com/klis87/normy",

packages/normy/README.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
<!-- [![Known Vulnerabilities](https://snyk.io/test/github/klis87/normy/badge.svg)](https://snyk.io/test/github/klis87/normy) -->
1212

13-
Automatic normalisation and data updates for data fetching libraries
13+
Automatic normalization and data updates for data fetching libraries
1414

1515
## Table of content
1616

1717
- [Introduction](#introduction-arrow_up)
1818
- [Motivation](#motivation-arrow_up)
1919
- [Installation](#installation-arrow_up)
2020
- [Required conditions](#required-conditions-arrow_up)
21-
- [Normalisation of arrays](#normalisation-of-arrays-arrow_up)
21+
- [Normalization of arrays](#normalization-of-arrays-arrow_up)
2222
- [Debugging](#debugging-arrow_up)
2323
- [Performance](#performance-arrow_up)
2424
- [Integrations](#examples-arrow_up)
@@ -158,22 +158,22 @@ in the future a guide will be created.
158158

159159
## Required conditions [:arrow_up:](#table-of-content)
160160

161-
In order to make automatic normalisation work, the following conditions must be met:
161+
In order to make automatic normalization work, the following conditions must be met:
162162

163163
1. you must have a standardized way to identify your objects, usually this is done by key `id`
164164
2. ids must be unique across the whole app, not only across object types, if not, you will need to append something to them,
165165
the same has to be done in GraphQL world, usually adding `_typename`
166166
3. objects with the same ids should have a consistent structure, if an object like book in one
167167
query has `title` key, it should be `title` in others, not `name` out of a sudden
168168

169-
There is a function which can be passed to `createQueryNormalizer` to meet those requirements, namely `getNormalisationObjectKey`.
169+
There is a function which can be passed to `createQueryNormalizer` to meet those requirements, namely `getNormalizationObjectKey`.
170170

171-
`getNormalisationObjectKey` can help you with 1st point, if for instance you identify
172-
objects differently, like by `_id` key, then you can pass `getNormalisationObjectKey: obj => obj._id`.
171+
`getNormalizationObjectKey` can help you with 1st point, if for instance you identify
172+
objects differently, like by `_id` key, then you can pass `getNormalizationObjectKey: obj => obj._id`.
173173

174-
`getNormalisationObjectKey` also allows you to pass the 2nd requirement. For example, if your ids
174+
`getNormalizationObjectKey` also allows you to pass the 2nd requirement. For example, if your ids
175175
are unique, but not across the whole app, but within object types, you could use
176-
`getNormalisationObjectKey: obj => obj.id && obj.type ? obj.id + obj.type : undefined` or something similar.
176+
`getNormalizationObjectKey: obj => obj.id && obj.type ? obj.id + obj.type : undefined` or something similar.
177177
If that is not possible, then you could just compute a suffix yourself, for example:
178178

179179
```js
@@ -190,15 +190,15 @@ const getType = obj => {
190190
};
191191

192192
createQueryNormalizer(queryClient, {
193-
getNormalisationObjectKey: obj =>
193+
getNormalizationObjectKey: obj =>
194194
obj.id && getType(obj) && obj.id + getType(obj),
195195
});
196196
```
197197

198198
Point 3 should always be met, if not, your really should ask your backend developers
199199
to keep things standardized and consistent. As a last resort, you can amend responses on your side.
200200

201-
## Normalisation of arrays [:arrow_up:](#table-of-content)
201+
## Normalization of arrays [:arrow_up:](#table-of-content)
202202

203203
Unfortunately it does not mean you will never need to update data manually anymore. Some updates still need
204204
to be done manually like usually, namely adding and removing items from array. Why? Imagine a `REMOVE_BOOK`
@@ -235,11 +235,11 @@ However, you have several flexible ways to improve performance:
235235
1. You can normalize only queries which have data updates, and only mutations which should update data - that's it,
236236
you can have only part of your data normalized. Check an integration documentation how to do it.
237237
2. Like `1.`, but for queries and mutations with extremely big data.
238-
3. You can use `getNormalisationObjectKey` function to set globally which objects should be actually normalized. For example:
238+
3. You can use `getNormalizationObjectKey` function to set globally which objects should be actually normalized. For example:
239239

240240
```js
241241
createQueryNormalizer(queryClient, {
242-
getNormalisationObjectKey: obj => (obj.normalizable ? obj.id : undefined),
242+
getNormalizationObjectKey: obj => (obj.normalizable ? obj.id : undefined),
243243
});
244244
```
245245

packages/normy/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@normy/core",
33
"version": "0.6.0",
4-
"description": "Automatic normalisation and data updates for data fetching libraries",
4+
"description": "Automatic normalization and data updates for data fetching libraries",
55
"main": "lib/index.js",
66
"module": "es/index.js",
77
"jsnext:main": "es/index.js",
@@ -11,7 +11,7 @@
1111
"license": "MIT",
1212
"typings": "types/index.d.ts",
1313
"keywords": [
14-
"normalisation",
14+
"normalization",
1515
"react-query"
1616
],
1717
"homepage": "https://github.com/klis87/normy",

packages/normy/src/create-normalizer.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ describe('createNormalizer', () => {
218218
});
219219
});
220220

221-
it('allows to override normalisation key', () => {
221+
it('allows to override normalization key', () => {
222222
const normalizer = createNormalizer({
223-
getNormalisationObjectKey: obj => obj._id as string,
223+
getNormalizationObjectKey: obj => obj._id as string,
224224
});
225225
normalizer.setQuery('query', {
226226
_id: '1',
@@ -243,9 +243,9 @@ describe('createNormalizer', () => {
243243
});
244244
});
245245

246-
it('allows to disable normalisation per object', () => {
246+
it('allows to disable normalization per object', () => {
247247
const normalizer = createNormalizer({
248-
getNormalisationObjectKey: obj => obj._id as string,
248+
getNormalizationObjectKey: obj => obj._id as string,
249249
});
250250
normalizer.setQuery('query', {
251251
_id: '1',

packages/normy/src/default-config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NormalizerConfig } from './types';
22

33
export const defaultConfig: Required<NormalizerConfig> = {
4-
getNormalisationObjectKey: obj => obj.id as string | undefined,
4+
getNormalizationObjectKey: obj => obj.id as string | undefined,
55
devLogging: false,
66
};

packages/normy/src/normalize.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,15 @@ describe('normalize', () => {
305305
]);
306306
});
307307

308-
it('should support configurable normalisation options', () => {
308+
it('should support configurable normalization options', () => {
309309
expect(
310310
normalize(
311311
[
312312
{ id: '1', key: 'a' },
313313
{ _id: '2', key: 'b' },
314314
],
315315
{
316-
getNormalisationObjectKey: obj =>
316+
getNormalizationObjectKey: obj =>
317317
obj._id && obj.key
318318
? `${obj._id as string}${obj.key as string}`
319319
: undefined,

packages/normy/src/normalize.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const stipFromDeps = (
2020
}
2121

2222
if (data !== null && typeof data === 'object') {
23-
const objectKey = config.getNormalisationObjectKey(data);
23+
const objectKey = config.getNormalizationObjectKey(data);
2424

2525
if (objectKey && root) {
2626
return `@@${objectKey}`;
@@ -58,7 +58,7 @@ export const getDependencies = (
5858
}
5959

6060
if (data !== null && typeof data === 'object') {
61-
if (config.getNormalisationObjectKey(data)) {
61+
if (config.getNormalizationObjectKey(data)) {
6262
usedKeys[path] = Object.keys(data);
6363
}
6464

@@ -68,7 +68,7 @@ export const getDependencies = (
6868
...prev,
6969
...getDependencies(v, config, usedKeys, `${path}.${k}`)[0],
7070
],
71-
config.getNormalisationObjectKey(data) ? [data] : [],
71+
config.getNormalizationObjectKey(data) ? [data] : [],
7272
),
7373
usedKeys,
7474
];
@@ -86,7 +86,7 @@ export const normalize = (
8686
return [
8787
stipFromDeps(data, config, true),
8888
dependencies.reduce((prev, v) => {
89-
const key = config.getNormalisationObjectKey(v) as string;
89+
const key = config.getNormalizationObjectKey(v) as string;
9090

9191
prev[`@@${key}`] = prev[`@@${key}`]
9292
? mergeData(prev[`@@${key}`], stipFromDeps(v, config, false))

packages/normy/src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export type Data =
1919
| DataObject[];
2020

2121
export type NormalizerConfig = {
22-
getNormalisationObjectKey?: (obj: DataObject) => string | undefined;
22+
getNormalizationObjectKey?: (obj: DataObject) => string | undefined;
2323
devLogging?: boolean;
2424
};
2525

0 commit comments

Comments
 (0)