UNPKG

react-native-cloud-store

Version:
78 lines (75 loc) 4.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.KVStoreChangedReason = void 0; exports.kvGetAllItems = kvGetAllItems; exports.kvGetItem = kvGetItem; exports.kvRemoveItem = kvRemoveItem; exports.kvSetItem = kvSetItem; exports.kvSync = kvSync; exports.onKVStoreRemoteChanged = onKVStoreRemoteChanged; exports.registerKVStoreRemoteChangedEvent = registerKVStoreRemoteChangedEvent; var _module = _interopRequireWildcard(require("./module")); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /** * From [official doc](https://developer.apple.com/documentation/foundation/nsubiquitouskeyvaluestore/1415989-synchronize): This method will call [synchronize()](https://developer.apple.com/documentation/foundation/nsubiquitouskeyvaluestore/1415989-synchronize) to explicitly synchronizes in-memory keys and values with those stored on disk. The only recommended time to call this method is upon app launch, or upon returning to the foreground, to ensure that the in-memory key-value store representation is up-to-date. */ async function kvSync() { return _module.default.kvSync(); } async function kvSetItem(key, value) { return _module.default.kvSetItem(key, value); } async function kvGetItem(key) { return _module.default.kvGetItem(key); } async function kvRemoveItem(key) { return _module.default.kvRemoveItem(key); } async function kvGetAllItems() { return _module.default.kvGetAllItems(); } /** * Change reasons, see [official doc](https://developer.apple.com/documentation/foundation/nsubiquitouskeyvaluestore/1433687-change_reason_values) for details */ let KVStoreChangedReason = exports.KVStoreChangedReason = /*#__PURE__*/function (KVStoreChangedReason) { KVStoreChangedReason[KVStoreChangedReason["NSUbiquitousKeyValueStoreServerChange"] = 0] = "NSUbiquitousKeyValueStoreServerChange"; KVStoreChangedReason[KVStoreChangedReason["NSUbiquitousKeyValueStoreInitialSyncChange"] = 1] = "NSUbiquitousKeyValueStoreInitialSyncChange"; KVStoreChangedReason[KVStoreChangedReason["NSUbiquitousKeyValueStoreQuotaViolationChange"] = 2] = "NSUbiquitousKeyValueStoreQuotaViolationChange"; KVStoreChangedReason[KVStoreChangedReason["NSUbiquitousKeyValueStoreAccountChange"] = 3] = "NSUbiquitousKeyValueStoreAccountChange"; return KVStoreChangedReason; }({}); let calledKVStoreRemoteChangedEvent = false; /** * Call this function at the beginning once to make `onKVStoreRemoteChanged` work */ function registerKVStoreRemoteChangedEvent() { if (calledKVStoreRemoteChangedEvent) { return; } calledKVStoreRemoteChangedEvent = true; _module.default.listenKvDidChangeExternallyNotification(); return { remove() { _module.default.unlistenKvDidChangeExternallyNotification(); calledKVStoreRemoteChangedEvent = false; } }; } /** * From [official doc](https://developer.apple.com/documentation/foundation/nsubiquitouskeyvaluestore/1412267-didchangeexternallynotification): This notification is sent only upon a change received from iCloud; it is not sent when your app sets a value. */ function onKVStoreRemoteChanged(fn) { if (!calledKVStoreRemoteChangedEvent) { console.error(`You didn't call registerKVStoreRemoteChangedEvent(), this listener will not trigger`); } return _module.eventEmitter.addListener('onKVStoreRemoteChanged', nativeData => { fn({ reason: nativeData.NSUbiquitousKeyValueStoreChangeReasonKey, changedKeys: nativeData.NSUbiquitousKeyValueStoreChangedKeysKey }); }); } //# sourceMappingURL=kv.js.map