Skip to content

Commit dcceeeb

Browse files
committed
Merge branch 'main' into feature/structural-sharing-cache-pr-4
2 parents 93a1478 + 8ae75ea commit dcceeeb

47 files changed

Lines changed: 2545 additions & 1925 deletions

Some content is hidden

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

.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: 28 additions & 177 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>
@@ -106,24 +72,9 @@ If the requested key is a collection, it will return an object with all the coll
10672
<dt><a href="#sendDataToConnection">sendDataToConnection()</a></dt>
10773
<dd><p>Sends the data obtained from the keys to the connection.</p>
10874
</dd>
109-
<dt><a href="#addKeyToRecentlyAccessedIfNeeded">addKeyToRecentlyAccessedIfNeeded()</a></dt>
110-
<dd><p>We check to see if this key is flagged as safe for eviction and add it to the recentlyAccessedKeys list so that when we
111-
run out of storage the least recently accessed key can be removed.</p>
112-
</dd>
11375
<dt><a href="#getCollectionDataAndSendAsObject">getCollectionDataAndSendAsObject()</a></dt>
11476
<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>
11577
</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>
12778
<dt><a href="#remove">remove()</a></dt>
12879
<dd><p>Remove a key from Onyx and update the subscribers</p>
12980
</dd>
@@ -194,6 +145,9 @@ that this internal function allows passing an additional <code>mergeReplaceNullP
194145
Any existing collection members not included in the new data will not be removed.
195146
Retries on failure.</p>
196147
</dd>
148+
<dt><a href="#getCallbackToStateMapping">getCallbackToStateMapping()</a></dt>
149+
<dd><p>Getter - returns the callback to state mapping, useful in test environments.</p>
150+
</dd>
197151
<dt><a href="#clearOnyxUtilsInternals">clearOnyxUtilsInternals()</a></dt>
198152
<dd><p>Clear internal variables used in this file, useful in test environments.</p>
199153
</dd>
@@ -223,6 +177,20 @@ Getter - returns the default key states.
223177
Getter - returns the deffered init task.
224178

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

228196
## getSkippableCollectionMemberIDs()
@@ -312,93 +280,6 @@ Deletes a subscription ID associated with its corresponding key.
312280
Returns current key names stored in persisted storage
313281

314282
**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-
402283
<a name="tryGetCachedValue"></a>
403284

404285
## tryGetCachedValue()
@@ -444,48 +325,12 @@ keyChanged(key, value, subscriber => subscriber.initWithStoredValues === false)
444325
## sendDataToConnection()
445326
Sends the data obtained from the keys to the connection.
446327

447-
**Kind**: global function
448-
<a name="addKeyToRecentlyAccessedIfNeeded"></a>
449-
450-
## addKeyToRecentlyAccessedIfNeeded()
451-
We check to see if this key is flagged as safe for eviction and add it to the recentlyAccessedKeys list so that when we
452-
run out of storage the least recently accessed key can be removed.
453-
454328
**Kind**: global function
455329
<a name="getCollectionDataAndSendAsObject"></a>
456330

457331
## getCollectionDataAndSendAsObject()
458332
Gets the data for a given an array of matching keys, combines them into an object, and sends the result back to the subscriber.
459333

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-
489334
**Kind**: global function
490335
<a name="remove"></a>
491336

@@ -677,6 +522,12 @@ Retries on failure.
677522
| params.collection | Object collection keyed by individual collection member keys and values |
678523
| retryAttempt | retry attempt |
679524

525+
<a name="getCallbackToStateMapping"></a>
526+
527+
## getCallbackToStateMapping()
528+
Getter - returns the callback to state mapping, useful in test environments.
529+
530+
**Kind**: global function
680531
<a name="clearOnyxUtilsInternals"></a>
681532

682533
## clearOnyxUtilsInternals()

0 commit comments

Comments
 (0)