react-native-onyx 1.0.130 → 2.0.1

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.
Files changed (71) hide show
  1. package/API.md +83 -22
  2. package/README.md +3 -13
  3. package/dist/DevTools.d.ts +23 -0
  4. package/{lib → dist}/DevTools.js +16 -18
  5. package/dist/Logger.js +32 -0
  6. package/dist/MDTable.d.ts +36 -0
  7. package/{lib → dist}/MDTable.js +12 -17
  8. package/{lib → dist}/Onyx.d.ts +0 -10
  9. package/{lib → dist}/Onyx.js +279 -583
  10. package/dist/OnyxCache.d.ts +121 -0
  11. package/{lib → dist}/OnyxCache.js +16 -53
  12. package/dist/Str.d.ts +18 -0
  13. package/dist/Str.js +31 -0
  14. package/dist/SyncQueue.d.ts +32 -0
  15. package/{lib → dist}/SyncQueue.js +9 -11
  16. package/dist/batch.d.ts +2 -0
  17. package/dist/batch.js +4 -0
  18. package/dist/batch.native.d.ts +2 -0
  19. package/dist/batch.native.js +4 -0
  20. package/dist/compose.d.ts +19 -0
  21. package/{lib → dist}/compose.js +5 -8
  22. package/dist/createDeferredTask.d.ts +12 -0
  23. package/{lib → dist}/createDeferredTask.js +4 -2
  24. package/dist/index.d.ts +6 -0
  25. package/dist/index.js +10 -0
  26. package/dist/metrics/PerformanceUtils.d.ts +14 -0
  27. package/{lib → dist}/metrics/PerformanceUtils.js +16 -16
  28. package/dist/metrics/index.d.ts +4 -0
  29. package/dist/metrics/index.js +14 -0
  30. package/dist/metrics/index.native.d.ts +43 -0
  31. package/{lib → dist}/metrics/index.native.js +80 -102
  32. package/{lib/storage/NativeStorage.js → dist/storage/NativeStorage.d.ts} +1 -2
  33. package/dist/storage/NativeStorage.js +7 -0
  34. package/dist/storage/WebStorage.d.ts +19 -0
  35. package/{lib → dist}/storage/WebStorage.js +24 -34
  36. package/dist/storage/__mocks__/index.d.ts +23 -0
  37. package/{lib → dist}/storage/__mocks__/index.js +17 -19
  38. package/{lib/storage/index.web.js → dist/storage/index.d.ts} +1 -2
  39. package/dist/storage/index.js +7 -0
  40. package/{lib/storage/index.native.js → dist/storage/index.native.d.ts} +1 -2
  41. package/dist/storage/index.native.js +7 -0
  42. package/dist/storage/providers/IDBKeyVal.d.ts +26 -0
  43. package/{lib → dist}/storage/providers/IDBKeyVal.js +38 -52
  44. package/dist/storage/providers/SQLiteStorage.d.ts +52 -0
  45. package/{lib → dist}/storage/providers/SQLiteStorage.js +27 -42
  46. package/{lib → dist}/utils.d.ts +2 -2
  47. package/{lib → dist}/utils.js +14 -27
  48. package/{lib → dist}/withOnyx.js +122 -159
  49. package/package.json +23 -58
  50. package/dist/web.development.js +0 -4593
  51. package/dist/web.development.js.map +0 -1
  52. package/dist/web.min.js +0 -2
  53. package/dist/web.min.js.map +0 -1
  54. package/lib/ActiveClientManager/index.d.ts +0 -22
  55. package/lib/ActiveClientManager/index.native.js +0 -18
  56. package/lib/ActiveClientManager/index.web.js +0 -94
  57. package/lib/Logger.js +0 -31
  58. package/lib/Str.js +0 -42
  59. package/lib/batch.js +0 -3
  60. package/lib/batch.native.js +0 -3
  61. package/lib/broadcast/index.d.ts +0 -17
  62. package/lib/broadcast/index.native.js +0 -12
  63. package/lib/broadcast/index.web.js +0 -33
  64. package/lib/index.d.ts +0 -6
  65. package/lib/index.js +0 -5
  66. package/lib/metrics/index.web.js +0 -10
  67. package/native.js +0 -11
  68. package/web.js +0 -12
  69. /package/{lib → dist}/Logger.d.ts +0 -0
  70. /package/{lib → dist}/types.d.ts +0 -0
  71. /package/{lib → dist}/withOnyx.d.ts +0 -0
@@ -1,94 +0,0 @@
1
- /**
2
- * When you have many tabs in one browser, the data of Onyx is shared between all of them. Since we persist write requests in Onyx, we need to ensure that
3
- * only one tab is processing those saved requests or we would be duplicating data (or creating errors).
4
- * This file ensures exactly that by tracking all the clientIDs connected, storing the most recent one last and it considers that last clientID the "leader".
5
- */
6
-
7
- import * as Str from '../Str';
8
- import * as Broadcast from '../broadcast';
9
-
10
- const NEW_LEADER_MESSAGE = 'NEW_LEADER';
11
- const REMOVED_LEADER_MESSAGE = 'REMOVE_LEADER';
12
-
13
- const clientID = Str.guid();
14
- const subscribers = [];
15
- let timestamp = null;
16
-
17
- let activeClientID = null;
18
- let setIsReady = () => {};
19
- const isReadyPromise = new Promise((resolve) => {
20
- setIsReady = resolve;
21
- });
22
-
23
- /**
24
- * Determines when the client is ready. We need to wait both till we saved our ID in onyx AND the init method was called
25
- * @returns {Promise}
26
- */
27
- function isReady() {
28
- return isReadyPromise;
29
- }
30
-
31
- /**
32
- * Returns a boolean indicating if the current client is the leader.
33
- *
34
- * @returns {Boolean}
35
- */
36
- function isClientTheLeader() {
37
- return activeClientID === clientID;
38
- }
39
-
40
- /**
41
- * Subscribes to when the client changes.
42
- * @param {Function} callback
43
- */
44
- function subscribeToClientChange(callback) {
45
- subscribers.push(callback);
46
- }
47
-
48
- /**
49
- * Subscribe to the broadcast channel to listen for messages from other tabs, so that
50
- * all tabs agree on who the leader is, which should always be the last tab to open.
51
- */
52
- function init() {
53
- Broadcast.subscribe((message) => {
54
- switch (message.data.type) {
55
- case NEW_LEADER_MESSAGE: {
56
- // Only update the active leader if the message received was from another
57
- // tab that initialized after the current one; if the timestamps are the
58
- // same, it uses the client ID to tie-break
59
- const isTimestampEqual = timestamp === message.data.timestamp;
60
- const isTimestampNewer = timestamp > message.data.timestamp;
61
- if (isClientTheLeader() && (isTimestampNewer || (isTimestampEqual && clientID > message.data.clientID))) {
62
- return;
63
- }
64
- activeClientID = message.data.clientID;
65
-
66
- subscribers.forEach((callback) => callback());
67
- break;
68
- }
69
- case REMOVED_LEADER_MESSAGE:
70
- activeClientID = clientID;
71
- timestamp = Date.now();
72
- Broadcast.sendMessage({type: NEW_LEADER_MESSAGE, clientID, timestamp});
73
- subscribers.forEach((callback) => callback());
74
- break;
75
- default:
76
- break;
77
- }
78
- });
79
-
80
- activeClientID = clientID;
81
- timestamp = Date.now();
82
-
83
- Broadcast.sendMessage({type: NEW_LEADER_MESSAGE, clientID, timestamp});
84
- setIsReady();
85
-
86
- window.addEventListener('beforeunload', () => {
87
- if (!isClientTheLeader()) {
88
- return;
89
- }
90
- Broadcast.sendMessage({type: REMOVED_LEADER_MESSAGE, clientID});
91
- });
92
- }
93
-
94
- export {isClientTheLeader, init, isReady, subscribeToClientChange};
package/lib/Logger.js DELETED
@@ -1,31 +0,0 @@
1
- // Logging callback
2
- let logger = () => {};
3
-
4
- /**
5
- * Register the logging callback
6
- *
7
- * @param {Function} callback
8
- */
9
- function registerLogger(callback) {
10
- logger = callback;
11
- }
12
-
13
- /**
14
- * Send an alert message to the logger
15
- *
16
- * @param {String} message
17
- */
18
- function logAlert(message) {
19
- logger({message: `[Onyx] ${message}`, level: 'alert'});
20
- }
21
-
22
- /**
23
- * Send an info message to the logger
24
- *
25
- * @param {String} message
26
- */
27
- function logInfo(message) {
28
- logger({message: `[Onyx] ${message}`, level: 'info'});
29
- }
30
-
31
- export {registerLogger, logInfo, logAlert};
package/lib/Str.js DELETED
@@ -1,42 +0,0 @@
1
- import _ from 'underscore';
2
-
3
- /**
4
- * Returns true if the haystack begins with the needle
5
- *
6
- * @param {String} haystack The full string to be searched
7
- * @param {String} needle The case-sensitive string to search for
8
- * @return {Boolean} Returns true if the haystack starts with the needle.
9
- */
10
- function startsWith(haystack, needle) {
11
- return _.isString(haystack) && _.isString(needle) && haystack.startsWith(needle);
12
- }
13
-
14
- /**
15
- * Checks if parameter is a string or function.
16
- * If it is a string, then we will just return it.
17
- * If it is a function, then we will call it with
18
- * any additional arguments and return the result.
19
- *
20
- * @param {String|Function} parameter
21
- * @returns {*}
22
- */
23
- function result(parameter, ...args) {
24
- return _.isFunction(parameter) ? parameter(...args) : parameter;
25
- }
26
-
27
- /**
28
- * A simple GUID generator taken from https://stackoverflow.com/a/32760401/9114791
29
- *
30
- * @param {String} [prefix] an optional prefix to put in front of the guid
31
- * @returns {String}
32
- */
33
- function guid(prefix = '') {
34
- function s4() {
35
- return Math.floor((1 + Math.random()) * 0x10000)
36
- .toString(16)
37
- .substring(1);
38
- }
39
- return `${prefix}${s4()}${s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`;
40
- }
41
-
42
- export {guid, startsWith, result};
package/lib/batch.js DELETED
@@ -1,3 +0,0 @@
1
- import {unstable_batchedUpdates} from 'react-dom';
2
-
3
- export default unstable_batchedUpdates;
@@ -1,3 +0,0 @@
1
- import {unstable_batchedUpdates} from 'react-native';
2
-
3
- export default unstable_batchedUpdates;
@@ -1,17 +0,0 @@
1
- /**
2
- * Sends a message to the broadcast channel.
3
- */
4
- declare function sendMessage(message: string): void;
5
-
6
- /**
7
- * Subscribes to the broadcast channel. Every time a new message
8
- * is received, the callback is called.
9
- */
10
- declare function subscribe(callback: () => {}): void;
11
-
12
- /**
13
- * Disconnects from the broadcast channel.
14
- */
15
- declare function disconnect(): void;
16
-
17
- export {sendMessage, subscribe, disconnect};
@@ -1,12 +0,0 @@
1
- /**
2
- * For native devices, there will never be more than one
3
- * client running at a time, so this lib is a big no-op
4
- */
5
-
6
- function sendMessage() {}
7
-
8
- function subscribe() {}
9
-
10
- function disconnect() {}
11
-
12
- export {sendMessage, subscribe, disconnect};
@@ -1,33 +0,0 @@
1
- const BROADCAST_ONYX = 'BROADCAST_ONYX';
2
-
3
- const subscriptions = [];
4
- const channel = new BroadcastChannel(BROADCAST_ONYX);
5
-
6
- /**
7
- * Sends a message to the broadcast channel.
8
- * @param {String} message
9
- */
10
- function sendMessage(message) {
11
- channel.postMessage(message);
12
- }
13
-
14
- /**
15
- * Subscribes to the broadcast channel. Every time a new message
16
- * is received, the callback is called.
17
- * @param {Function} callback
18
- */
19
- function subscribe(callback) {
20
- subscriptions.push(callback);
21
- channel.onmessage = (message) => {
22
- subscriptions.forEach((c) => c(message));
23
- };
24
- }
25
-
26
- /**
27
- * Disconnects from the broadcast channel.
28
- */
29
- function disconnect() {
30
- channel.close();
31
- }
32
-
33
- export {sendMessage, subscribe, disconnect};
package/lib/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import Onyx, {OnyxUpdate, ConnectOptions} from './Onyx';
2
- import {CustomTypeOptions, OnyxCollection, OnyxEntry} from './types';
3
- import withOnyx from './withOnyx';
4
-
5
- export default Onyx;
6
- export {CustomTypeOptions, OnyxCollection, OnyxEntry, OnyxUpdate, withOnyx, ConnectOptions};
package/lib/index.js DELETED
@@ -1,5 +0,0 @@
1
- import Onyx from './Onyx';
2
- import withOnyx from './withOnyx';
3
-
4
- export default Onyx;
5
- export {withOnyx};
@@ -1,10 +0,0 @@
1
- // For web-only implementations of Onyx, this module will just be a no-op
2
-
3
- function decorateWithMetrics(func) {
4
- return func;
5
- }
6
- function getMetrics() {}
7
- function printMetrics() {}
8
- function resetMetrics() {}
9
-
10
- export {decorateWithMetrics, getMetrics, resetMetrics, printMetrics};
package/native.js DELETED
@@ -1,11 +0,0 @@
1
- /**
2
- * @file
3
- * Native entry point for Onyx
4
- * This file is resolved by react-native projects
5
- */
6
- import Onyx from './lib';
7
-
8
- // We resolve pure source for react-native projects and let `metro` bundle it
9
- // We can test small changes directly from the parent project `node_modules/react-native-onyx` source
10
- export * from './lib';
11
- export default Onyx;
package/web.js DELETED
@@ -1,12 +0,0 @@
1
- /**
2
- * @file
3
- * Web entry point for Onyx
4
- * This file is resolved by non react-native projects
5
- * Like React for web or pure JS
6
- */
7
-
8
- if (process.env.NODE_ENV === 'production') {
9
- module.exports = require('./dist/web.min');
10
- } else {
11
- module.exports = require('./dist/web.development');
12
- }
File without changes
File without changes
File without changes