Skip to content

Commit beb4681

Browse files
committed
Merge branch 'main' into @chrispader/update-nitro-sqlite-to-v9.6.0
2 parents 5e44d80 + d2000b5 commit beb4681

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2412
-1416
lines changed

.github/scripts/verifyDocs.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
#
3+
# Re-generates API docs and verifies that there is no diff,
4+
# because that would indicate that the PR author forgot to run `npm run build:docs`
5+
# and commit the updated API.md and API-INTERNAL.md files.
6+
7+
declare -r GREEN='\033[0;32m'
8+
declare -r RED='\033[0;31m'
9+
declare -r NC='\033[0m'
10+
11+
printf '\nRebuilding API docs...\n'
12+
if ! npm run build:docs; then
13+
echo -e "${RED}Error: \`npm run build:docs\` failed. Please fix the build errors before continuing.${NC}"
14+
exit 1
15+
fi
16+
17+
DIFF_OUTPUT=$(git diff --exit-code API.md API-INTERNAL.md)
18+
EXIT_CODE=$?
19+
20+
if [[ EXIT_CODE -eq 0 ]]; then
21+
echo -e "${GREEN}API docs are up to date!${NC}"
22+
exit 0
23+
else
24+
echo -e "${RED}Error: Diff found when API docs were rebuilt. Did you forget to run \`npm run build:docs\` after making changes?${NC}"
25+
echo "$DIFF_OUTPUT"
26+
exit 1
27+
fi

.github/workflows/validateDocs.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Validate API Docs
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
paths: ['lib/**', 'buildDocs.ts', 'API.md', 'API-INTERNAL.md', '.github/workflows/validateDocs.yml', '.github/scripts/verifyDocs.sh']
7+
8+
jobs:
9+
verify:
10+
runs-on: ubuntu-latest
11+
steps:
12+
# v5.0.0
13+
- uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493
14+
15+
- name: Setup Node
16+
# v4.4.0
17+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e
18+
with:
19+
node-version-file: ".nvmrc"
20+
cache: npm
21+
cache-dependency-path: package-lock.json
22+
23+
- run: npm ci
24+
25+
- name: Verify API Docs Are Up To Date
26+
run: ./.github/scripts/verifyDocs.sh

API-INTERNAL.md

Lines changed: 19 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
<dt><a href="#getDeferredInitTask">getDeferredInitTask()</a></dt>
1818
<dd><p>Getter - returns the deffered init task.</p>
1919
</dd>
20+
<dt><a href="#afterInit">afterInit(action)</a> ⇒</dt>
21+
<dd><p>Executes an action after Onyx has been initialized.
22+
If Onyx is already initialized, the action is executed immediately.
23+
Otherwise, it waits for initialization to complete before executing.</p>
24+
</dd>
2025
<dt><a href="#getSkippableCollectionMemberIDs">getSkippableCollectionMemberIDs()</a></dt>
2126
<dd><p>Getter - returns the skippable collection member IDs.</p>
2227
</dd>
@@ -54,45 +59,6 @@ to the values for those keys (correctly typed) such as <code>[OnyxCollection&lt;
5459
<dt><a href="#getAllKeys">getAllKeys()</a></dt>
5560
<dd><p>Returns current key names stored in persisted storage</p>
5661
</dd>
57-
<dt><a href="#getCollectionKeys">getCollectionKeys()</a></dt>
58-
<dd><p>Returns set of all registered collection keys</p>
59-
</dd>
60-
<dt><a href="#isCollectionKey">isCollectionKey()</a></dt>
61-
<dd><p>Checks to see if the subscriber&#39;s supplied key
62-
is associated with a collection of keys.</p>
63-
</dd>
64-
<dt><a href="#isCollectionMember">isCollectionMember(key)</a> ⇒</dt>
65-
<dd><p>Checks if a given key is a collection member key (not just a collection key).</p>
66-
</dd>
67-
<dt><a href="#isRamOnlyKey">isRamOnlyKey(key)</a> ⇒</dt>
68-
<dd><p>Checks if a given key is a RAM-only key, RAM-only collection key, or a RAM-only collection member</p>
69-
<p>For example:</p>
70-
<p>For the following Onyx setup</p>
71-
<p>ramOnlyKeys: [&quot;ramOnlyKey&quot;, &quot;ramOnlyCollection_&quot;]</p>
72-
<ul>
73-
<li><code>isRamOnlyKey(&quot;ramOnlyKey&quot;)</code> would return true</li>
74-
<li><code>isRamOnlyKey(&quot;ramOnlyCollection_&quot;)</code> would return true</li>
75-
<li><code>isRamOnlyKey(&quot;ramOnlyCollection_1&quot;)</code> would return true</li>
76-
<li><code>isRamOnlyKey(&quot;someOtherKey&quot;)</code> would return false</li>
77-
</ul>
78-
</dd>
79-
<dt><a href="#splitCollectionMemberKey">splitCollectionMemberKey(key, collectionKey)</a> ⇒</dt>
80-
<dd><p>Splits a collection member key into the collection key part and the ID part.</p>
81-
</dd>
82-
<dt><a href="#isKeyMatch">isKeyMatch()</a></dt>
83-
<dd><p>Checks to see if a provided key is the exact configured key of our connected subscriber
84-
or if the provided key is a collection member key (in case our configured key is a &quot;collection key&quot;)</p>
85-
</dd>
86-
<dt><a href="#getCollectionKey">getCollectionKey(key)</a> ⇒</dt>
87-
<dd><p>Extracts the collection identifier of a given collection member key.</p>
88-
<p>For example:</p>
89-
<ul>
90-
<li><code>getCollectionKey(&quot;report_123&quot;)</code> would return &quot;report_&quot;</li>
91-
<li><code>getCollectionKey(&quot;report_&quot;)</code> would return &quot;report_&quot;</li>
92-
<li><code>getCollectionKey(&quot;report_-1_something&quot;)</code> would return &quot;report_&quot;</li>
93-
<li><code>getCollectionKey(&quot;sharedNVP_user_-1_something&quot;)</code> would return &quot;sharedNVP_user_&quot;</li>
94-
</ul>
95-
</dd>
9662
<dt><a href="#tryGetCachedValue">tryGetCachedValue()</a></dt>
9763
<dd><p>Tries to get a value from the cache. If the value is not present in cache it will return the default value or undefined.
9864
If the requested key is a collection, it will return an object with all the collection members.</p>
@@ -113,17 +79,6 @@ run out of storage the least recently accessed key can be removed.</p>
11379
<dt><a href="#getCollectionDataAndSendAsObject">getCollectionDataAndSendAsObject()</a></dt>
11480
<dd><p>Gets the data for a given an array of matching keys, combines them into an object, and sends the result back to the subscriber.</p>
11581
</dd>
116-
<dt><a href="#prepareSubscriberUpdate">prepareSubscriberUpdate(callback)</a></dt>
117-
<dd><p>Delays promise resolution until the next macrotask to prevent race condition if the key subscription is in progress.</p>
118-
</dd>
119-
<dt><a href="#scheduleSubscriberUpdate">scheduleSubscriberUpdate()</a></dt>
120-
<dd><p>Schedules an update that will be appended to the macro task queue (so it doesn&#39;t update the subscribers immediately).</p>
121-
</dd>
122-
<dt><a href="#scheduleNotifyCollectionSubscribers">scheduleNotifyCollectionSubscribers()</a></dt>
123-
<dd><p>This method is similar to scheduleSubscriberUpdate but it is built for working specifically with collections
124-
so that keysChanged() is triggered for the collection and not keyChanged(). If this was not done, then the
125-
subscriber callbacks receive the data in a different format than they normally expect and it breaks code.</p>
126-
</dd>
12782
<dt><a href="#remove">remove()</a></dt>
12883
<dd><p>Remove a key from Onyx and update the subscribers</p>
12984
</dd>
@@ -223,6 +178,20 @@ Getter - returns the default key states.
223178
Getter - returns the deffered init task.
224179

225180
**Kind**: global function
181+
<a name="afterInit"></a>
182+
183+
## afterInit(action) ⇒
184+
Executes an action after Onyx has been initialized.
185+
If Onyx is already initialized, the action is executed immediately.
186+
Otherwise, it waits for initialization to complete before executing.
187+
188+
**Kind**: global function
189+
**Returns**: The result of the action
190+
191+
| Param | Description |
192+
| --- | --- |
193+
| action | The action to execute after initialization |
194+
226195
<a name="getSkippableCollectionMemberIDs"></a>
227196

228197
## getSkippableCollectionMemberIDs()
@@ -312,93 +281,6 @@ Deletes a subscription ID associated with its corresponding key.
312281
Returns current key names stored in persisted storage
313282

314283
**Kind**: global function
315-
<a name="getCollectionKeys"></a>
316-
317-
## getCollectionKeys()
318-
Returns set of all registered collection keys
319-
320-
**Kind**: global function
321-
<a name="isCollectionKey"></a>
322-
323-
## isCollectionKey()
324-
Checks to see if the subscriber's supplied key
325-
is associated with a collection of keys.
326-
327-
**Kind**: global function
328-
<a name="isCollectionMember"></a>
329-
330-
## isCollectionMember(key) ⇒
331-
Checks if a given key is a collection member key (not just a collection key).
332-
333-
**Kind**: global function
334-
**Returns**: true if the key is a collection member, false otherwise
335-
336-
| Param | Description |
337-
| --- | --- |
338-
| key | The key to check |
339-
340-
<a name="isRamOnlyKey"></a>
341-
342-
## isRamOnlyKey(key) ⇒
343-
Checks if a given key is a RAM-only key, RAM-only collection key, or a RAM-only collection member
344-
345-
For example:
346-
347-
For the following Onyx setup
348-
349-
ramOnlyKeys: ["ramOnlyKey", "ramOnlyCollection_"]
350-
351-
- `isRamOnlyKey("ramOnlyKey")` would return true
352-
- `isRamOnlyKey("ramOnlyCollection_")` would return true
353-
- `isRamOnlyKey("ramOnlyCollection_1")` would return true
354-
- `isRamOnlyKey("someOtherKey")` would return false
355-
356-
**Kind**: global function
357-
**Returns**: true if key is a RAM-only key, RAM-only collection key, or a RAM-only collection member
358-
359-
| Param | Description |
360-
| --- | --- |
361-
| key | The key to check |
362-
363-
<a name="splitCollectionMemberKey"></a>
364-
365-
## splitCollectionMemberKey(key, collectionKey) ⇒
366-
Splits a collection member key into the collection key part and the ID part.
367-
368-
**Kind**: global function
369-
**Returns**: A tuple where the first element is the collection part and the second element is the ID part,
370-
or throws an Error if the key is not a collection one.
371-
372-
| Param | Description |
373-
| --- | --- |
374-
| key | The collection member key to split. |
375-
| collectionKey | The collection key of the `key` param that can be passed in advance to optimize the function. |
376-
377-
<a name="isKeyMatch"></a>
378-
379-
## isKeyMatch()
380-
Checks to see if a provided key is the exact configured key of our connected subscriber
381-
or if the provided key is a collection member key (in case our configured key is a "collection key")
382-
383-
**Kind**: global function
384-
<a name="getCollectionKey"></a>
385-
386-
## getCollectionKey(key) ⇒
387-
Extracts the collection identifier of a given collection member key.
388-
389-
For example:
390-
- `getCollectionKey("report_123")` would return "report_"
391-
- `getCollectionKey("report_")` would return "report_"
392-
- `getCollectionKey("report_-1_something")` would return "report_"
393-
- `getCollectionKey("sharedNVP_user_-1_something")` would return "sharedNVP_user_"
394-
395-
**Kind**: global function
396-
**Returns**: The plain collection key or throws an Error if the key is not a collection one.
397-
398-
| Param | Description |
399-
| --- | --- |
400-
| key | The collection key to process. |
401-
402284
<a name="tryGetCachedValue"></a>
403285

404286
## tryGetCachedValue()
@@ -457,35 +339,6 @@ run out of storage the least recently accessed key can be removed.
457339
## getCollectionDataAndSendAsObject()
458340
Gets the data for a given an array of matching keys, combines them into an object, and sends the result back to the subscriber.
459341

460-
**Kind**: global function
461-
<a name="prepareSubscriberUpdate"></a>
462-
463-
## prepareSubscriberUpdate(callback)
464-
Delays promise resolution until the next macrotask to prevent race condition if the key subscription is in progress.
465-
466-
**Kind**: global function
467-
468-
| Param | Description |
469-
| --- | --- |
470-
| callback | The keyChanged/keysChanged callback |
471-
472-
<a name="scheduleSubscriberUpdate"></a>
473-
474-
## scheduleSubscriberUpdate()
475-
Schedules an update that will be appended to the macro task queue (so it doesn't update the subscribers immediately).
476-
477-
**Kind**: global function
478-
**Example**
479-
```js
480-
scheduleSubscriberUpdate(key, value, subscriber => subscriber.initWithStoredValues === false)
481-
```
482-
<a name="scheduleNotifyCollectionSubscribers"></a>
483-
484-
## scheduleNotifyCollectionSubscribers()
485-
This method is similar to scheduleSubscriberUpdate but it is built for working specifically with collections
486-
so that keysChanged() is triggered for the collection and not keyChanged(). If this was not done, then the
487-
subscriber callbacks receive the data in a different format than they normally expect and it breaks code.
488-
489342
**Kind**: global function
490343
<a name="remove"></a>
491344

README.md

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -351,59 +351,6 @@ const ReportActionsView = ({reportID, isActiveReport}) => {
351351
export default ReportActionsView;
352352
```
353353

354-
# Benchmarks
355-
356-
Provide the `captureMetrics` boolean flag to `Onyx.init` to capture call statistics
357-
358-
```js
359-
Onyx.init({
360-
keys: ONYXKEYS,
361-
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
362-
captureMetrics: Config.BENCHMARK_ONYX,
363-
});
364-
```
365-
366-
At any point you can get the collected statistics using `Onyx.getMetrics()`.
367-
This will return an object containing `totalTime`, `averageTime` and `summaries`.
368-
`summaries` is a collection of statistics for each method it contains data about:
369-
- method name
370-
- total, max, min, average times for this method calls
371-
- calls - a list of individual calls with each having: start time; end time; call duration; call arguments
372-
- start/end times are relative to application launch time - 0.00 being exactly at launch
373-
374-
If you wish to reset the metrics and start over use `Onyx.resetMetrics()`
375-
376-
Finally, there's a `Onyx.printMetrics()` method which prints human statistics information on the dev console. You can use this method during debugging. For example add an `Onyx.printMetrics()` line somewhere in code or call it through the dev console. It supports 3 popular formats *MD* - human friendly markdown, *CSV* and *JSON*. The default is MD if you want to print another format call `Onyx.printMetrics({ format: 'csv' })` or
377-
`Onyx.printMetrics({ format: 'json' })`.
378-
379-
Sample output of `Onyx.printMetrics()`
380-
381-
```
382-
### Onyx Benchmark
383-
- Total: 1.5min
384-
- Last call finished at: 12.55sec
385-
386-
| method | total time spent | max | min | avg | time last call completed | calls made |
387-
|-----------------|-----------------:|----------:|---------:|----------:|-------------------------:|-----------:|
388-
| Onyx:getAllKeys | 1.2min | 2.16sec | 0.159ms | 782.230ms | 12.55sec | 90 |
389-
| Onyx:merge | 4.73sec | 2.00sec | 74.412ms | 591.642ms | 10.24sec | 8 |
390-
| Onyx:set | 3.90sec | 846.760ms | 43.663ms | 433.056ms | 7.47sec | 9 |
391-
| Onyx:get | 8.87sec | 2.00sec | 0.063ms | 61.998ms | 10.24sec | 143 |
392-
393-
394-
| Onyx:set |
395-
|---------------------------------------------------------------|
396-
| start time | end time | duration | args |
397-
|-----------:|----------:|----------:|--------------------------|
398-
| 291.042ms | 553.079ms | 262.037ms | session, [object Object] |
399-
| 293.719ms | 553.316ms | 259.597ms | account, [object Object] |
400-
| 294.541ms | 553.651ms | 259.109ms | network, [object Object] |
401-
| 365.378ms | 554.246ms | 188.867ms | iou, [object Object] |
402-
| 1.08sec | 2.20sec | 1.12sec | network, [object Object] |
403-
| 1.08sec | 2.20sec | 1.12sec | iou, [object Object] |
404-
| 1.17sec | 2.20sec | 1.03sec | currentURL, / |
405-
```
406-
407354
# Debug mode
408355

409356
It can be useful to log why Onyx is calling `setState()` on a particular React component so that we can understand which key changed, what changed about the value, and the connected component that ultimately rendered as a result. When used correctly this can help isolate problem areas and unnecessary renders in the code. To enable this feature, pass `debugSetState: true` to the config and grep JS console logs for `[Onyx-Debug]`.

lib/DevTools/RealDevTools.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {IDevTools, DevtoolsOptions, DevtoolsConnection, ReduxDevtools} from './types';
2+
import OnyxKeys from '../OnyxKeys';
23

34
const ERROR_LABEL = 'Onyx DevTools - Error: ';
45

@@ -76,7 +77,7 @@ class RealDevTools implements IDevTools {
7677
clearState(keysToPreserve: string[] = []): void {
7778
const newState = Object.entries(this.state).reduce((obj: Record<string, unknown>, [key, value]) => {
7879
// eslint-disable-next-line no-param-reassign
79-
obj[key] = keysToPreserve.includes(key) ? value : this.defaultState[key];
80+
obj[key] = keysToPreserve.some((preserveKey) => OnyxKeys.isKeyMatch(preserveKey, key)) ? value : this.defaultState[key];
8081
return obj;
8182
}, {});
8283

lib/GlobalSettings.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)