@ionic/portals-react-native 0.0.1 → 0.0.4

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.
@@ -1,27 +1,37 @@
1
1
  import Foundation
2
2
  import IonicPortals
3
+ import IonicLiveUpdates
3
4
  import React
4
5
  import UIKit
6
+ import Capacitor
5
7
 
6
8
  @objc(IONPortalManager)
7
- class PortalManager: NSObject {
8
- private typealias IonPortalManager = IonicPortals.PortalManager
9
+ public class PortalManager: NSObject {
10
+ private static var portals: [String: Portal] = [:]
11
+
12
+ public static func register(_ key: String) {
13
+ PortalsRegistrationManager.shared.register(key: key)
14
+ }
15
+
16
+ public static func add(_ portal: Portal) {
17
+ portals[portal.name] = portal
18
+ }
19
+
20
+ static func getPortal(named name: String) -> Portal? { portals[name] }
9
21
 
10
22
  @objc func register(_ key: String) {
11
- IonPortalManager.register(key)
23
+ Self.register(key)
12
24
  }
13
25
 
14
26
  @objc func addPortal(_ portalDict: [String: Any]) {
15
- guard let name = portalDict["name"] as? String else { return }
16
- let portal = Portal(name, portalDict["startDir"] as? String)
17
- portal.initialContext = portalDict["initialContext"] as? [String: Any]
18
- IonPortalManager.addPortal(portal)
27
+ guard let portal = Portal(portalDict) else { return }
28
+ Self.add(portal)
19
29
  }
20
30
 
21
31
  @objc static func requiresMainQueueSetup() -> Bool { true }
22
32
  }
23
33
 
24
- @objc(IONPortalsPubSub)
34
+ @objc(IONPortalPubSub)
25
35
  class PortalsPubSub: RCTEventEmitter {
26
36
  private let eventName = "PortalsSubscription"
27
37
 
@@ -30,7 +40,7 @@ class PortalsPubSub: RCTEventEmitter {
30
40
  }
31
41
 
32
42
  @objc func subscribe(_ topic: String, resolver: RCTPromiseResolveBlock, rejector: RCTPromiseRejectBlock) {
33
- let subRef = PortalsPlugin.subscribe(topic) { [weak self] result in
43
+ let subRef = IonicPortals.PortalsPubSub.subscribe(topic) { [weak self] result in
34
44
  guard let self = self else { return }
35
45
  self.sendEvent(
36
46
  withName: self.eventName,
@@ -45,12 +55,12 @@ class PortalsPubSub: RCTEventEmitter {
45
55
  resolver(subRef)
46
56
  }
47
57
 
48
- @objc func unsubscribe(_ topic: String, subscriptionRef: Int) {
49
- PortalsPlugin.unsubscribe(topic, subscriptionRef)
58
+ @objc func unsubscribe(_ topic: String, subscriptionRef: NSNumber) {
59
+ IonicPortals.PortalsPubSub.unsubscribe(from: topic, subscriptionRef: subscriptionRef.intValue)
50
60
  }
51
61
 
52
62
  @objc func publish(_ topic: String, data: Any) {
53
- PortalsPlugin.publish(topic, data)
63
+ IONPortalsPubSub.publish(message: data, topic: topic)
54
64
  }
55
65
 
56
66
  override class func requiresMainQueueSetup() -> Bool { true }
@@ -63,7 +73,7 @@ class PortalViewManager: RCTViewManager {
63
73
  }
64
74
 
65
75
  class PortalView: UIView {
66
- private var webView: PortalWebView?
76
+ private var webView: PortalUIView?
67
77
 
68
78
  @objc var name: String? {
69
79
  get {
@@ -73,7 +83,7 @@ class PortalView: UIView {
73
83
 
74
84
  set {
75
85
  guard let portalName = newValue else { return }
76
- _portal = try? IonicPortals.PortalManager.getPortal(portalName)
86
+ _portal = PortalManager.getPortal(named: portalName)
77
87
  }
78
88
  }
79
89
 
@@ -85,8 +95,8 @@ class PortalView: UIView {
85
95
 
86
96
  set {
87
97
  guard let name = name else { return }
88
- _portal = try? IonicPortals.PortalManager.getPortal(name)
89
- _portal?.initialContext = newValue
98
+ _portal = PortalManager.getPortal(named: name)
99
+ _portal?.initialContext = JSTypes.coerceDictionaryToJSObject(newValue) ?? [:]
90
100
  }
91
101
  }
92
102
 
@@ -96,7 +106,7 @@ class PortalView: UIView {
96
106
  DispatchQueue.main.async { [weak self] in
97
107
  guard let self = self else { return }
98
108
  self.webView?.removeFromSuperview()
99
- let webView = PortalWebView(portal: portal)
109
+ let webView = PortalUIView(portal: portal)
100
110
  webView.translatesAutoresizingMaskIntoConstraints = false
101
111
  self.addSubview(webView)
102
112
  NSLayoutConstraint.activate([
@@ -111,3 +121,142 @@ class PortalView: UIView {
111
121
  }
112
122
  }
113
123
 
124
+ extension Portal {
125
+ init?(_ dict: [String: Any]) {
126
+ guard let name = dict["name"] as? String else { return nil }
127
+ self.init(
128
+ name: name,
129
+ startDir: dict["startDir"] as? String,
130
+ initialContext: JSTypes.coerceDictionaryToJSObject(dict["initialContext"] as? [String: Any]) ?? [:],
131
+ liveUpdateConfig: (dict["liveUpdate"] as? [String: Any]).flatMap(LiveUpdate.init)
132
+ )
133
+ }
134
+ }
135
+
136
+ extension LiveUpdate {
137
+ init?(_ dict: [String: Any]) {
138
+ guard let appId = dict["appId"] as? String,
139
+ let channel = dict["channel"] as? String,
140
+ let syncOnAdd = dict["syncOnAdd"] as? Bool
141
+ else { return nil }
142
+
143
+ self.init(appId: appId, channel: channel, syncOnAdd: syncOnAdd)
144
+ }
145
+ }
146
+
147
+ extension LiveUpdate {
148
+ var dict: [String: Any] {
149
+ return [
150
+ "appId": appId,
151
+ "channel": channel,
152
+ "syncOnAdd": syncOnAdd
153
+ ]
154
+ }
155
+ }
156
+
157
+ extension LiveUpdateManager.Error {
158
+ var dict: [String: Any] {
159
+ return [
160
+ "appId": appId,
161
+ "failStep": failStep.rawValue.uppercased(),
162
+ "message": localizedDescription
163
+ ]
164
+ }
165
+ }
166
+
167
+ private struct SyncResults {
168
+ var liveUpdates: [LiveUpdate]
169
+ var errors: [LiveUpdateManager.Error]
170
+ }
171
+
172
+ extension SyncResults {
173
+ var dict: [String: Any] {
174
+ return [
175
+ "liveUpdates": liveUpdates.map(\.dict),
176
+ "errors": errors.map(\.dict)
177
+ ]
178
+ }
179
+ }
180
+
181
+ @objc(IONLiveUpdatesManager)
182
+ public class LiveUpdatesManager: NSObject {
183
+ private var lum = LiveUpdateManager.shared
184
+
185
+ @objc func addLiveUpdate(_ dict: [String: Any]) {
186
+ guard let liveUpdate = LiveUpdate(dict) else { return }
187
+ try? lum.add(liveUpdate)
188
+ }
189
+
190
+ @objc func syncOne(_ appId: String, resolver: @escaping RCTPromiseResolveBlock, rejector: @escaping RCTPromiseRejectBlock) {
191
+ lum.sync(appId: appId, isParallel: true) { result in
192
+ switch result {
193
+ case .success(let update):
194
+ resolver(update.dict)
195
+ case .failure(let error):
196
+ rejector(nil, nil, error)
197
+ }
198
+ }
199
+ }
200
+
201
+ @objc func syncSome(_ appIds: [String], resolver: @escaping RCTPromiseResolveBlock, rejector: RCTPromiseRejectBlock) {
202
+ Task {
203
+ let syncResult = await lum.syncSome(appIds)
204
+ resolver(syncResult.dict)
205
+ }
206
+ }
207
+
208
+ @objc func syncAll(_ resolver: @escaping RCTPromiseResolveBlock, rejector: RCTPromiseRejectBlock) {
209
+ Task {
210
+ let syncResult = await lum.syncAll()
211
+ resolver(syncResult.dict)
212
+ }
213
+ }
214
+
215
+ @objc static func requiresMainQueueSetup() -> Bool { true }
216
+ }
217
+
218
+ extension LiveUpdateManager {
219
+ fileprivate func syncSome(_ appIds: [String]) async -> SyncResults {
220
+ await _syncSome(appIds).syncResults
221
+ }
222
+
223
+ private func _syncSome(_ appIds: [String]) -> AsyncStream<Result<LiveUpdate, LiveUpdateManager.Error>> {
224
+ AsyncStream { continuation in
225
+ sync(appIds: appIds, isParallel: true) {
226
+ continuation.finish()
227
+ } appComplete: { result in
228
+ continuation.yield(result)
229
+ }
230
+ }
231
+ }
232
+
233
+ fileprivate func syncAll() async -> SyncResults {
234
+ await _syncAll().syncResults
235
+ }
236
+
237
+
238
+ private func _syncAll() -> AsyncStream<Result<LiveUpdate, LiveUpdateManager.Error>> {
239
+ AsyncStream { continuation in
240
+ sync(isParallel: true) {
241
+ continuation.finish()
242
+ } appComplete: { result in
243
+ continuation.yield(result)
244
+ }
245
+ }
246
+ }
247
+ }
248
+
249
+ extension AsyncStream where Element == Result<LiveUpdate, LiveUpdateManager.Error> {
250
+ fileprivate var syncResults: SyncResults {
251
+ get async {
252
+ await reduce(into: SyncResults(liveUpdates: [], errors: [])) { acc, next in
253
+ switch next {
254
+ case .success(let liveUpdate):
255
+ acc.liveUpdates.append(liveUpdate)
256
+ case .failure(let error):
257
+ acc.errors.append(error)
258
+ }
259
+ }
260
+ }
261
+ }
262
+ }
@@ -13,6 +13,7 @@
13
13
  A7128A0827F7A16200DADDF3 /* ReactNativePortals-Bridging-Header.h in Headers */ = {isa = PBXBuildFile; fileRef = F4FF95D5245B92E700C19C63 /* ReactNativePortals-Bridging-Header.h */; };
14
14
  A7128A0927F7A16200DADDF3 /* PortalsPubSub.m in Sources */ = {isa = PBXBuildFile; fileRef = A71289F827F79D4000DADDF3 /* PortalsPubSub.m */; };
15
15
  A7128A0A27F7A16200DADDF3 /* PortalView.m in Sources */ = {isa = PBXBuildFile; fileRef = A71289F727F79CDC00DADDF3 /* PortalView.m */; };
16
+ A748ABFC28626EC300F26852 /* LiveUpdatesManager.m in Sources */ = {isa = PBXBuildFile; fileRef = A748ABFB28626EC300F26852 /* LiveUpdatesManager.m */; };
16
17
  /* End PBXBuildFile section */
17
18
 
18
19
  /* Begin PBXFileReference section */
@@ -21,6 +22,7 @@
21
22
  A71289F827F79D4000DADDF3 /* PortalsPubSub.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PortalsPubSub.m; sourceTree = "<group>"; };
22
23
  A71289F927F79EB200DADDF3 /* PortalManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PortalManager.m; sourceTree = "<group>"; };
23
24
  A71289FF27F7A14900DADDF3 /* ReactNativePortals.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ReactNativePortals.framework; sourceTree = BUILT_PRODUCTS_DIR; };
25
+ A748ABFB28626EC300F26852 /* LiveUpdatesManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LiveUpdatesManager.m; sourceTree = "<group>"; };
24
26
  CB9439A9444D2E97DA3B8149 /* Pods-ReactNativePortals.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativePortals.debug.xcconfig"; path = "Target Support Files/Pods-ReactNativePortals/Pods-ReactNativePortals.debug.xcconfig"; sourceTree = "<group>"; };
25
27
  F4FF95D5245B92E700C19C63 /* ReactNativePortals-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ReactNativePortals-Bridging-Header.h"; sourceTree = "<group>"; };
26
28
  F4FF95D6245B92E800C19C63 /* ReactNativePortals.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactNativePortals.swift; sourceTree = "<group>"; };
@@ -57,6 +59,7 @@
57
59
  58B511D21A9E6C8500147676 = {
58
60
  isa = PBXGroup;
59
61
  children = (
62
+ A748ABFB28626EC300F26852 /* LiveUpdatesManager.m */,
60
63
  F4FF95D6245B92E800C19C63 /* ReactNativePortals.swift */,
61
64
  A71289F727F79CDC00DADDF3 /* PortalView.m */,
62
65
  A71289F927F79EB200DADDF3 /* PortalManager.m */,
@@ -183,6 +186,7 @@
183
186
  isa = PBXSourcesBuildPhase;
184
187
  buildActionMask = 2147483647;
185
188
  files = (
189
+ A748ABFC28626EC300F26852 /* LiveUpdatesManager.m in Sources */,
186
190
  A7128A0A27F7A16200DADDF3 /* PortalView.m in Sources */,
187
191
  A7128A0927F7A16200DADDF3 /* PortalsPubSub.m in Sources */,
188
192
  A7128A0627F7A16200DADDF3 /* ReactNativePortals.swift in Sources */,
@@ -13,7 +13,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
13
13
 
14
14
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
15
 
16
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
16
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
17
17
 
18
18
  const PortalViewManager = (0, _reactNative.requireNativeComponent)('AndroidPortalView');
19
19
 
@@ -1 +1 @@
1
- {"version":3,"sources":["PortalView.android.tsx"],"names":["PortalViewManager","createFragment","viewId","UIManager","dispatchViewManagerCommand","AndroidPortalView","Commands","create","toString","PortalView","props","ref","current"],"mappings":";;;;;;;AAAA;;AACA;;;;;;;;AAOA,MAAMA,iBAAiB,GAAG,yCAAuB,mBAAvB,CAA1B;;AAEA,MAAMC,cAAc,GAAIC,MAAD,IACrBC,uBAAUC,0BAAV,CACEF,MADF,EAEE;AACA;AACAC,uBAAUE,iBAAV,CAA4BC,QAA5B,CAAqCC,MAArC,CAA4CC,QAA5C,EAJF,EAKE,CAACN,MAAD,CALF,CADF;;AASA,MAAMO,UAAU,GAAIC,KAAD,IAAwB;AACzC,QAAMC,GAAG,GAAG,mBAAO,IAAP,CAAZ;AAEA,wBAAU,MAAM;AACd,UAAMT,MAAM,GAAG,iCAAeS,GAAG,CAACC,OAAnB,CAAf;AACAX,IAAAA,cAAc,CAACC,MAAD,CAAd;AACD,GAHD,EAGG,EAHH;AAKA,sBAAO,6BAAC,iBAAD,eAAuBQ,KAAvB;AAA8B,IAAA,GAAG,EAAEC;AAAnC,KAAP;AACD,CATD;;eAWeF,U","sourcesContent":["import React, { useEffect, useRef } from 'react';\nimport {\n findNodeHandle,\n requireNativeComponent,\n UIManager,\n} from 'react-native';\nimport type { PortalProps } from '.';\n\nconst PortalViewManager = requireNativeComponent('AndroidPortalView');\n\nconst createFragment = (viewId: number | null) =>\n UIManager.dispatchViewManagerCommand(\n viewId,\n // we are calling the 'create' command\n // @ts-expect-error\n UIManager.AndroidPortalView.Commands.create.toString(),\n [viewId]\n );\n\nconst PortalView = (props: PortalProps) => {\n const ref = useRef(null);\n\n useEffect(() => {\n const viewId = findNodeHandle(ref.current);\n createFragment(viewId);\n }, []);\n\n return <PortalViewManager {...props} ref={ref} />;\n};\n\nexport default PortalView;\n"]}
1
+ {"version":3,"names":["PortalViewManager","requireNativeComponent","createFragment","viewId","UIManager","dispatchViewManagerCommand","AndroidPortalView","Commands","create","toString","PortalView","props","ref","useRef","useEffect","findNodeHandle","current"],"sources":["PortalView.android.tsx"],"sourcesContent":["import React, { useEffect, useRef } from 'react';\nimport {\n findNodeHandle,\n requireNativeComponent,\n UIManager,\n} from 'react-native';\nimport type { PortalProps } from '.';\n\nconst PortalViewManager = requireNativeComponent('AndroidPortalView');\n\nconst createFragment = (viewId: number | null) =>\n UIManager.dispatchViewManagerCommand(\n viewId,\n // we are calling the 'create' command\n // @ts-expect-error\n UIManager.AndroidPortalView.Commands.create.toString(),\n [viewId]\n );\n\nconst PortalView = (props: PortalProps) => {\n const ref = useRef(null);\n\n useEffect(() => {\n const viewId = findNodeHandle(ref.current);\n createFragment(viewId);\n }, []);\n\n return <PortalViewManager {...props} ref={ref} />;\n};\n\nexport default PortalView;\n"],"mappings":";;;;;;;AAAA;;AACA;;;;;;;;AAOA,MAAMA,iBAAiB,GAAG,IAAAC,mCAAA,EAAuB,mBAAvB,CAA1B;;AAEA,MAAMC,cAAc,GAAIC,MAAD,IACrBC,sBAAA,CAAUC,0BAAV,CACEF,MADF,EAEE;AACA;AACAC,sBAAA,CAAUE,iBAAV,CAA4BC,QAA5B,CAAqCC,MAArC,CAA4CC,QAA5C,EAJF,EAKE,CAACN,MAAD,CALF,CADF;;AASA,MAAMO,UAAU,GAAIC,KAAD,IAAwB;EACzC,MAAMC,GAAG,GAAG,IAAAC,aAAA,EAAO,IAAP,CAAZ;EAEA,IAAAC,gBAAA,EAAU,MAAM;IACd,MAAMX,MAAM,GAAG,IAAAY,2BAAA,EAAeH,GAAG,CAACI,OAAnB,CAAf;IACAd,cAAc,CAACC,MAAD,CAAd;EACD,CAHD,EAGG,EAHH;EAKA,oBAAO,6BAAC,iBAAD,eAAuBQ,KAAvB;IAA8B,GAAG,EAAEC;EAAnC,GAAP;AACD,CATD;;eAWeF,U"}
@@ -1 +1 @@
1
- {"version":3,"sources":["PortalView.tsx"],"names":["HostComponentPortal","PortalView","props"],"mappings":";;;;;;;AAAA;;AACA;;;;AAGA,MAAMA,mBAAmB,GAAG,yCAAuB,eAAvB,CAA5B;;AAEA,MAAMC,UAAU,GAAIC,KAAD,IAAwB;AACzC,sBAAO,6BAAC,mBAAD,EAAyBA,KAAzB,CAAP;AACD,CAFD;;eAIeD,U","sourcesContent":["import React from 'react';\nimport { requireNativeComponent } from 'react-native';\nimport type { PortalProps } from '.';\n\nconst HostComponentPortal = requireNativeComponent('IONPortalView');\n\nconst PortalView = (props: PortalProps) => {\n return <HostComponentPortal {...props} />;\n};\n\nexport default PortalView;\n"]}
1
+ {"version":3,"names":["HostComponentPortal","requireNativeComponent","PortalView","props"],"sources":["PortalView.tsx"],"sourcesContent":["import React from 'react';\nimport { requireNativeComponent } from 'react-native';\nimport type { PortalProps } from '.';\n\nconst HostComponentPortal = requireNativeComponent('IONPortalView');\n\nconst PortalView = (props: PortalProps) => {\n return <HostComponentPortal {...props} />;\n};\n\nexport default PortalView;\n"],"mappings":";;;;;;;AAAA;;AACA;;;;AAGA,MAAMA,mBAAmB,GAAG,IAAAC,mCAAA,EAAuB,eAAvB,CAA5B;;AAEA,MAAMC,UAAU,GAAIC,KAAD,IAAwB;EACzC,oBAAO,6BAAC,mBAAD,EAAyBA,KAAzB,CAAP;AACD,CAFD;;eAIeD,U"}
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "PortalView", {
9
9
  return _PortalView.default;
10
10
  }
11
11
  });
12
- exports.unsubscribe = exports.subscribe = exports.register = exports.publish = exports.addPortal = void 0;
12
+ exports.unsubscribe = exports.syncSome = exports.syncOne = exports.syncAll = exports.subscribe = exports.register = exports.publish = exports.addPortal = void 0;
13
13
 
14
14
  var _reactNative = require("react-native");
15
15
 
@@ -18,23 +18,34 @@ var _PortalView = _interopRequireDefault(require("./PortalView"));
18
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
19
 
20
20
  const {
21
- IONPortalsPubSub,
22
- IONPortalManager
21
+ IONPortalPubSub,
22
+ IONPortalManager,
23
+ IONLiveUpdatesManager
23
24
  } = _reactNative.NativeModules;
24
- const PortalsPubSub = new _reactNative.NativeEventEmitter(IONPortalsPubSub);
25
- let subscriptionRefDict = {};
25
+ const PortalsPubSub = new _reactNative.NativeEventEmitter(IONPortalPubSub);
26
+ const subscriptionMap = new Map();
26
27
 
27
28
  const subscribe = async (topic, onMessageReceived) => {
28
- const subscriptionRef = await IONPortalsPubSub.subscribe(topic);
29
- subscriptionRefDict[subscriptionRef] = PortalsPubSub.addListener('PortalsSubscription', onMessageReceived);
29
+ const subscriptionRef = await IONPortalPubSub.subscribe(topic);
30
+ const subscriber = PortalsPubSub.addListener('PortalsSubscription', message => {
31
+ if (message.subscriptionRef === subscriptionRef) {
32
+ onMessageReceived(message);
33
+ }
34
+ });
35
+ subscriptionMap.set(subscriptionRef, subscriber);
30
36
  return subscriptionRef;
31
37
  };
32
38
 
33
39
  exports.subscribe = subscribe;
34
40
 
35
41
  const unsubscribe = (topic, subRef) => {
36
- IONPortalsPubSub.unsubscribe(topic, subRef);
37
- subscriptionRefDict[subRef] = null;
42
+ IONPortalPubSub.unsubscribe(topic, subRef);
43
+ const subscription = subscriptionMap.get(subRef);
44
+
45
+ if (subscription !== undefined) {
46
+ subscription.remove();
47
+ subscriptionMap.delete(subRef);
48
+ }
38
49
  };
39
50
 
40
51
  exports.unsubscribe = unsubscribe;
@@ -43,7 +54,7 @@ const publish = (topic, data) => {
43
54
  const msg = {
44
55
  message: data
45
56
  };
46
- IONPortalsPubSub.publish(topic, msg);
57
+ IONPortalPubSub.publish(topic, msg);
47
58
  };
48
59
 
49
60
  exports.publish = publish;
@@ -59,4 +70,22 @@ const addPortal = portal => {
59
70
  };
60
71
 
61
72
  exports.addPortal = addPortal;
73
+
74
+ const syncOne = appId => {
75
+ return IONLiveUpdatesManager.syncOne(appId);
76
+ };
77
+
78
+ exports.syncOne = syncOne;
79
+
80
+ const syncSome = appIds => {
81
+ return IONLiveUpdatesManager.syncSome(appIds);
82
+ };
83
+
84
+ exports.syncSome = syncSome;
85
+
86
+ const syncAll = () => {
87
+ return IONLiveUpdatesManager.syncAll();
88
+ };
89
+
90
+ exports.syncAll = syncAll;
62
91
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":["IONPortalsPubSub","IONPortalManager","NativeModules","PortalsPubSub","NativeEventEmitter","subscriptionRefDict","subscribe","topic","onMessageReceived","subscriptionRef","addListener","unsubscribe","subRef","publish","data","msg","message","register","key","addPortal","portal"],"mappings":";;;;;;;;;;;;;AAAA;;AAIA;;;;AAFA,MAAM;AAAEA,EAAAA,gBAAF;AAAoBC,EAAAA;AAApB,IAAyCC,0BAA/C;AAUA,MAAMC,aAAa,GAAG,IAAIC,+BAAJ,CAAuBJ,gBAAvB,CAAtB;AAEA,IAAIK,mBAAwB,GAAG,EAA/B;;AAEO,MAAMC,SAAS,GAAG,OACvBC,KADuB,EAEvBC,iBAFuB,KAGH;AACpB,QAAMC,eAAe,GAAG,MAAMT,gBAAgB,CAACM,SAAjB,CAA2BC,KAA3B,CAA9B;AACAF,EAAAA,mBAAmB,CAACI,eAAD,CAAnB,GAAuCN,aAAa,CAACO,WAAd,CACrC,qBADqC,EAErCF,iBAFqC,CAAvC;AAIA,SAAOC,eAAP;AACD,CAVM;;;;AAYA,MAAME,WAAW,GAAG,CAACJ,KAAD,EAAgBK,MAAhB,KAAmC;AAC5DZ,EAAAA,gBAAgB,CAACW,WAAjB,CAA6BJ,KAA7B,EAAoCK,MAApC;AACAP,EAAAA,mBAAmB,CAACO,MAAD,CAAnB,GAA8B,IAA9B;AACD,CAHM;;;;AAKA,MAAMC,OAAO,GAAG,CAACN,KAAD,EAAgBO,IAAhB,KAA8B;AACnD,QAAMC,GAAG,GAAG;AAAEC,IAAAA,OAAO,EAAEF;AAAX,GAAZ;AACAd,EAAAA,gBAAgB,CAACa,OAAjB,CAAyBN,KAAzB,EAAgCQ,GAAhC;AACD,CAHM;;;;AAKA,MAAME,QAAQ,GAAIC,GAAD,IAAiB;AACvCjB,EAAAA,gBAAgB,CAACgB,QAAjB,CAA0BC,GAA1B;AACD,CAFM;;;;AAYA,MAAMC,SAAS,GAAIC,MAAD,IAAoB;AAC3CnB,EAAAA,gBAAgB,CAACkB,SAAjB,CAA2BC,MAA3B;AACD,CAFM","sourcesContent":["import { NativeEventEmitter, NativeModules, ViewProps } from 'react-native';\n\nconst { IONPortalsPubSub, IONPortalManager } = NativeModules;\n\nexport { default as PortalView } from './PortalView';\n\nexport interface Message {\n subscriptionRef: number;\n data: any;\n topic: string;\n}\n\nconst PortalsPubSub = new NativeEventEmitter(IONPortalsPubSub);\n\nlet subscriptionRefDict: any = {};\n\nexport const subscribe = async (\n topic: string,\n onMessageReceived: (message: Message) => void\n): Promise<number> => {\n const subscriptionRef = await IONPortalsPubSub.subscribe(topic);\n subscriptionRefDict[subscriptionRef] = PortalsPubSub.addListener(\n 'PortalsSubscription',\n onMessageReceived\n );\n return subscriptionRef;\n};\n\nexport const unsubscribe = (topic: string, subRef: number) => {\n IONPortalsPubSub.unsubscribe(topic, subRef);\n subscriptionRefDict[subRef] = null;\n};\n\nexport const publish = (topic: string, data: any) => {\n const msg = { message: data };\n IONPortalsPubSub.publish(topic, msg);\n};\n\nexport const register = (key: string) => {\n IONPortalManager.register(key);\n};\n\nexport interface Portal {\n name: string;\n startDir?: string;\n initialContext?: any;\n}\n\nexport type PortalProps = Pick<Portal, 'name' | 'initialContext'> & ViewProps;\n\nexport const addPortal = (portal: Portal) => {\n IONPortalManager.addPortal(portal);\n};\n"]}
1
+ {"version":3,"names":["IONPortalPubSub","IONPortalManager","IONLiveUpdatesManager","NativeModules","PortalsPubSub","NativeEventEmitter","subscriptionMap","Map","subscribe","topic","onMessageReceived","subscriptionRef","subscriber","addListener","message","set","unsubscribe","subRef","subscription","get","undefined","remove","delete","publish","data","msg","register","key","addPortal","portal","syncOne","appId","syncSome","appIds","syncAll"],"sources":["index.ts"],"sourcesContent":["import {\n EmitterSubscription,\n NativeEventEmitter,\n NativeModules,\n ViewProps,\n} from 'react-native';\n\nconst { IONPortalPubSub, IONPortalManager, IONLiveUpdatesManager } =\n NativeModules;\n\nexport { default as PortalView } from './PortalView';\n\nexport interface Message {\n subscriptionRef: number;\n data: any;\n topic: string;\n}\n\nconst PortalsPubSub = new NativeEventEmitter(IONPortalPubSub);\n\nconst subscriptionMap = new Map<number, EmitterSubscription>();\n\nexport const subscribe = async (\n topic: string,\n onMessageReceived: (message: Message) => void\n): Promise<number> => {\n const subscriptionRef = await IONPortalPubSub.subscribe(topic);\n\n const subscriber = PortalsPubSub.addListener(\n 'PortalsSubscription',\n (message: Message) => {\n if (message.subscriptionRef === subscriptionRef) {\n onMessageReceived(message);\n }\n }\n );\n\n subscriptionMap.set(subscriptionRef, subscriber);\n\n return subscriptionRef;\n};\n\nexport const unsubscribe = (topic: string, subRef: number) => {\n IONPortalPubSub.unsubscribe(topic, subRef);\n\n const subscription = subscriptionMap.get(subRef);\n if (subscription !== undefined) {\n subscription.remove();\n subscriptionMap.delete(subRef);\n }\n};\n\nexport const publish = (topic: string, data: any) => {\n const msg = { message: data };\n IONPortalPubSub.publish(topic, msg);\n};\n\nexport const register = (key: string) => {\n IONPortalManager.register(key);\n};\n\nexport interface Portal {\n name: string;\n androidPlugins?: string[];\n startDir?: string;\n initialContext?: {\n [key: string]: any;\n };\n liveUpdate?: LiveUpdateConfig;\n}\n\nexport type PortalProps = Pick<Portal, 'name' | 'initialContext'> & ViewProps;\n\nexport const addPortal = (portal: Portal) => {\n IONPortalManager.addPortal(portal);\n};\n\nexport interface LiveUpdate {\n appId: string;\n channel: string;\n}\n\nexport type LiveUpdateConfig = LiveUpdate & { syncOnAdd: boolean };\n\nexport interface LiveUpdateError {\n appId: string;\n failStep: string;\n message: string;\n}\n\nexport interface SyncResults {\n liveUpdates: LiveUpdate[];\n errors: LiveUpdateError[];\n}\n\nexport const syncOne = (appId: string): Promise<LiveUpdate> => {\n return IONLiveUpdatesManager.syncOne(appId);\n};\n\nexport const syncSome = (appIds: string[]): Promise<SyncResults> => {\n return IONLiveUpdatesManager.syncSome(appIds);\n};\n\nexport const syncAll = (): Promise<SyncResults> => {\n return IONLiveUpdatesManager.syncAll();\n};\n"],"mappings":";;;;;;;;;;;;;AAAA;;AAUA;;;;AAHA,MAAM;EAAEA,eAAF;EAAmBC,gBAAnB;EAAqCC;AAArC,IACJC,0BADF;AAWA,MAAMC,aAAa,GAAG,IAAIC,+BAAJ,CAAuBL,eAAvB,CAAtB;AAEA,MAAMM,eAAe,GAAG,IAAIC,GAAJ,EAAxB;;AAEO,MAAMC,SAAS,GAAG,OACvBC,KADuB,EAEvBC,iBAFuB,KAGH;EACpB,MAAMC,eAAe,GAAG,MAAMX,eAAe,CAACQ,SAAhB,CAA0BC,KAA1B,CAA9B;EAEA,MAAMG,UAAU,GAAGR,aAAa,CAACS,WAAd,CACjB,qBADiB,EAEhBC,OAAD,IAAsB;IACpB,IAAIA,OAAO,CAACH,eAAR,KAA4BA,eAAhC,EAAiD;MAC/CD,iBAAiB,CAACI,OAAD,CAAjB;IACD;EACF,CANgB,CAAnB;EASAR,eAAe,CAACS,GAAhB,CAAoBJ,eAApB,EAAqCC,UAArC;EAEA,OAAOD,eAAP;AACD,CAlBM;;;;AAoBA,MAAMK,WAAW,GAAG,CAACP,KAAD,EAAgBQ,MAAhB,KAAmC;EAC5DjB,eAAe,CAACgB,WAAhB,CAA4BP,KAA5B,EAAmCQ,MAAnC;EAEA,MAAMC,YAAY,GAAGZ,eAAe,CAACa,GAAhB,CAAoBF,MAApB,CAArB;;EACA,IAAIC,YAAY,KAAKE,SAArB,EAAgC;IAC9BF,YAAY,CAACG,MAAb;IACAf,eAAe,CAACgB,MAAhB,CAAuBL,MAAvB;EACD;AACF,CARM;;;;AAUA,MAAMM,OAAO,GAAG,CAACd,KAAD,EAAgBe,IAAhB,KAA8B;EACnD,MAAMC,GAAG,GAAG;IAAEX,OAAO,EAAEU;EAAX,CAAZ;EACAxB,eAAe,CAACuB,OAAhB,CAAwBd,KAAxB,EAA+BgB,GAA/B;AACD,CAHM;;;;AAKA,MAAMC,QAAQ,GAAIC,GAAD,IAAiB;EACvC1B,gBAAgB,CAACyB,QAAjB,CAA0BC,GAA1B;AACD,CAFM;;;;AAgBA,MAAMC,SAAS,GAAIC,MAAD,IAAoB;EAC3C5B,gBAAgB,CAAC2B,SAAjB,CAA2BC,MAA3B;AACD,CAFM;;;;AAsBA,MAAMC,OAAO,GAAIC,KAAD,IAAwC;EAC7D,OAAO7B,qBAAqB,CAAC4B,OAAtB,CAA8BC,KAA9B,CAAP;AACD,CAFM;;;;AAIA,MAAMC,QAAQ,GAAIC,MAAD,IAA4C;EAClE,OAAO/B,qBAAqB,CAAC8B,QAAtB,CAA+BC,MAA/B,CAAP;AACD,CAFM;;;;AAIA,MAAMC,OAAO,GAAG,MAA4B;EACjD,OAAOhC,qBAAqB,CAACgC,OAAtB,EAAP;AACD,CAFM"}
@@ -1,4 +1,4 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
 
3
3
  import React, { useEffect, useRef } from 'react';
4
4
  import { findNodeHandle, requireNativeComponent, UIManager } from 'react-native';
@@ -1 +1 @@
1
- {"version":3,"sources":["PortalView.android.tsx"],"names":["React","useEffect","useRef","findNodeHandle","requireNativeComponent","UIManager","PortalViewManager","createFragment","viewId","dispatchViewManagerCommand","AndroidPortalView","Commands","create","toString","PortalView","props","ref","current"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,SAAhB,EAA2BC,MAA3B,QAAyC,OAAzC;AACA,SACEC,cADF,EAEEC,sBAFF,EAGEC,SAHF,QAIO,cAJP;AAOA,MAAMC,iBAAiB,GAAGF,sBAAsB,CAAC,mBAAD,CAAhD;;AAEA,MAAMG,cAAc,GAAIC,MAAD,IACrBH,SAAS,CAACI,0BAAV,CACED,MADF,EAEE;AACA;AACAH,SAAS,CAACK,iBAAV,CAA4BC,QAA5B,CAAqCC,MAArC,CAA4CC,QAA5C,EAJF,EAKE,CAACL,MAAD,CALF,CADF;;AASA,MAAMM,UAAU,GAAIC,KAAD,IAAwB;AACzC,QAAMC,GAAG,GAAGd,MAAM,CAAC,IAAD,CAAlB;AAEAD,EAAAA,SAAS,CAAC,MAAM;AACd,UAAMO,MAAM,GAAGL,cAAc,CAACa,GAAG,CAACC,OAAL,CAA7B;AACAV,IAAAA,cAAc,CAACC,MAAD,CAAd;AACD,GAHQ,EAGN,EAHM,CAAT;AAKA,sBAAO,oBAAC,iBAAD,eAAuBO,KAAvB;AAA8B,IAAA,GAAG,EAAEC;AAAnC,KAAP;AACD,CATD;;AAWA,eAAeF,UAAf","sourcesContent":["import React, { useEffect, useRef } from 'react';\nimport {\n findNodeHandle,\n requireNativeComponent,\n UIManager,\n} from 'react-native';\nimport type { PortalProps } from '.';\n\nconst PortalViewManager = requireNativeComponent('AndroidPortalView');\n\nconst createFragment = (viewId: number | null) =>\n UIManager.dispatchViewManagerCommand(\n viewId,\n // we are calling the 'create' command\n // @ts-expect-error\n UIManager.AndroidPortalView.Commands.create.toString(),\n [viewId]\n );\n\nconst PortalView = (props: PortalProps) => {\n const ref = useRef(null);\n\n useEffect(() => {\n const viewId = findNodeHandle(ref.current);\n createFragment(viewId);\n }, []);\n\n return <PortalViewManager {...props} ref={ref} />;\n};\n\nexport default PortalView;\n"]}
1
+ {"version":3,"names":["React","useEffect","useRef","findNodeHandle","requireNativeComponent","UIManager","PortalViewManager","createFragment","viewId","dispatchViewManagerCommand","AndroidPortalView","Commands","create","toString","PortalView","props","ref","current"],"sources":["PortalView.android.tsx"],"sourcesContent":["import React, { useEffect, useRef } from 'react';\nimport {\n findNodeHandle,\n requireNativeComponent,\n UIManager,\n} from 'react-native';\nimport type { PortalProps } from '.';\n\nconst PortalViewManager = requireNativeComponent('AndroidPortalView');\n\nconst createFragment = (viewId: number | null) =>\n UIManager.dispatchViewManagerCommand(\n viewId,\n // we are calling the 'create' command\n // @ts-expect-error\n UIManager.AndroidPortalView.Commands.create.toString(),\n [viewId]\n );\n\nconst PortalView = (props: PortalProps) => {\n const ref = useRef(null);\n\n useEffect(() => {\n const viewId = findNodeHandle(ref.current);\n createFragment(viewId);\n }, []);\n\n return <PortalViewManager {...props} ref={ref} />;\n};\n\nexport default PortalView;\n"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,SAAhB,EAA2BC,MAA3B,QAAyC,OAAzC;AACA,SACEC,cADF,EAEEC,sBAFF,EAGEC,SAHF,QAIO,cAJP;AAOA,MAAMC,iBAAiB,GAAGF,sBAAsB,CAAC,mBAAD,CAAhD;;AAEA,MAAMG,cAAc,GAAIC,MAAD,IACrBH,SAAS,CAACI,0BAAV,CACED,MADF,EAEE;AACA;AACAH,SAAS,CAACK,iBAAV,CAA4BC,QAA5B,CAAqCC,MAArC,CAA4CC,QAA5C,EAJF,EAKE,CAACL,MAAD,CALF,CADF;;AASA,MAAMM,UAAU,GAAIC,KAAD,IAAwB;EACzC,MAAMC,GAAG,GAAGd,MAAM,CAAC,IAAD,CAAlB;EAEAD,SAAS,CAAC,MAAM;IACd,MAAMO,MAAM,GAAGL,cAAc,CAACa,GAAG,CAACC,OAAL,CAA7B;IACAV,cAAc,CAACC,MAAD,CAAd;EACD,CAHQ,EAGN,EAHM,CAAT;EAKA,oBAAO,oBAAC,iBAAD,eAAuBO,KAAvB;IAA8B,GAAG,EAAEC;EAAnC,GAAP;AACD,CATD;;AAWA,eAAeF,UAAf"}
@@ -1 +1 @@
1
- {"version":3,"sources":["PortalView.tsx"],"names":["React","requireNativeComponent","HostComponentPortal","PortalView","props"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,sBAAT,QAAuC,cAAvC;AAGA,MAAMC,mBAAmB,GAAGD,sBAAsB,CAAC,eAAD,CAAlD;;AAEA,MAAME,UAAU,GAAIC,KAAD,IAAwB;AACzC,sBAAO,oBAAC,mBAAD,EAAyBA,KAAzB,CAAP;AACD,CAFD;;AAIA,eAAeD,UAAf","sourcesContent":["import React from 'react';\nimport { requireNativeComponent } from 'react-native';\nimport type { PortalProps } from '.';\n\nconst HostComponentPortal = requireNativeComponent('IONPortalView');\n\nconst PortalView = (props: PortalProps) => {\n return <HostComponentPortal {...props} />;\n};\n\nexport default PortalView;\n"]}
1
+ {"version":3,"names":["React","requireNativeComponent","HostComponentPortal","PortalView","props"],"sources":["PortalView.tsx"],"sourcesContent":["import React from 'react';\nimport { requireNativeComponent } from 'react-native';\nimport type { PortalProps } from '.';\n\nconst HostComponentPortal = requireNativeComponent('IONPortalView');\n\nconst PortalView = (props: PortalProps) => {\n return <HostComponentPortal {...props} />;\n};\n\nexport default PortalView;\n"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,sBAAT,QAAuC,cAAvC;AAGA,MAAMC,mBAAmB,GAAGD,sBAAsB,CAAC,eAAD,CAAlD;;AAEA,MAAME,UAAU,GAAIC,KAAD,IAAwB;EACzC,oBAAO,oBAAC,mBAAD,EAAyBA,KAAzB,CAAP;AACD,CAFD;;AAIA,eAAeD,UAAf"}
@@ -1,25 +1,36 @@
1
1
  import { NativeEventEmitter, NativeModules } from 'react-native';
2
2
  const {
3
- IONPortalsPubSub,
4
- IONPortalManager
3
+ IONPortalPubSub,
4
+ IONPortalManager,
5
+ IONLiveUpdatesManager
5
6
  } = NativeModules;
6
7
  export { default as PortalView } from './PortalView';
7
- const PortalsPubSub = new NativeEventEmitter(IONPortalsPubSub);
8
- let subscriptionRefDict = {};
8
+ const PortalsPubSub = new NativeEventEmitter(IONPortalPubSub);
9
+ const subscriptionMap = new Map();
9
10
  export const subscribe = async (topic, onMessageReceived) => {
10
- const subscriptionRef = await IONPortalsPubSub.subscribe(topic);
11
- subscriptionRefDict[subscriptionRef] = PortalsPubSub.addListener('PortalsSubscription', onMessageReceived);
11
+ const subscriptionRef = await IONPortalPubSub.subscribe(topic);
12
+ const subscriber = PortalsPubSub.addListener('PortalsSubscription', message => {
13
+ if (message.subscriptionRef === subscriptionRef) {
14
+ onMessageReceived(message);
15
+ }
16
+ });
17
+ subscriptionMap.set(subscriptionRef, subscriber);
12
18
  return subscriptionRef;
13
19
  };
14
20
  export const unsubscribe = (topic, subRef) => {
15
- IONPortalsPubSub.unsubscribe(topic, subRef);
16
- subscriptionRefDict[subRef] = null;
21
+ IONPortalPubSub.unsubscribe(topic, subRef);
22
+ const subscription = subscriptionMap.get(subRef);
23
+
24
+ if (subscription !== undefined) {
25
+ subscription.remove();
26
+ subscriptionMap.delete(subRef);
27
+ }
17
28
  };
18
29
  export const publish = (topic, data) => {
19
30
  const msg = {
20
31
  message: data
21
32
  };
22
- IONPortalsPubSub.publish(topic, msg);
33
+ IONPortalPubSub.publish(topic, msg);
23
34
  };
24
35
  export const register = key => {
25
36
  IONPortalManager.register(key);
@@ -27,4 +38,13 @@ export const register = key => {
27
38
  export const addPortal = portal => {
28
39
  IONPortalManager.addPortal(portal);
29
40
  };
41
+ export const syncOne = appId => {
42
+ return IONLiveUpdatesManager.syncOne(appId);
43
+ };
44
+ export const syncSome = appIds => {
45
+ return IONLiveUpdatesManager.syncSome(appIds);
46
+ };
47
+ export const syncAll = () => {
48
+ return IONLiveUpdatesManager.syncAll();
49
+ };
30
50
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":["NativeEventEmitter","NativeModules","IONPortalsPubSub","IONPortalManager","default","PortalView","PortalsPubSub","subscriptionRefDict","subscribe","topic","onMessageReceived","subscriptionRef","addListener","unsubscribe","subRef","publish","data","msg","message","register","key","addPortal","portal"],"mappings":"AAAA,SAASA,kBAAT,EAA6BC,aAA7B,QAA6D,cAA7D;AAEA,MAAM;AAAEC,EAAAA,gBAAF;AAAoBC,EAAAA;AAApB,IAAyCF,aAA/C;AAEA,SAASG,OAAO,IAAIC,UAApB,QAAsC,cAAtC;AAQA,MAAMC,aAAa,GAAG,IAAIN,kBAAJ,CAAuBE,gBAAvB,CAAtB;AAEA,IAAIK,mBAAwB,GAAG,EAA/B;AAEA,OAAO,MAAMC,SAAS,GAAG,OACvBC,KADuB,EAEvBC,iBAFuB,KAGH;AACpB,QAAMC,eAAe,GAAG,MAAMT,gBAAgB,CAACM,SAAjB,CAA2BC,KAA3B,CAA9B;AACAF,EAAAA,mBAAmB,CAACI,eAAD,CAAnB,GAAuCL,aAAa,CAACM,WAAd,CACrC,qBADqC,EAErCF,iBAFqC,CAAvC;AAIA,SAAOC,eAAP;AACD,CAVM;AAYP,OAAO,MAAME,WAAW,GAAG,CAACJ,KAAD,EAAgBK,MAAhB,KAAmC;AAC5DZ,EAAAA,gBAAgB,CAACW,WAAjB,CAA6BJ,KAA7B,EAAoCK,MAApC;AACAP,EAAAA,mBAAmB,CAACO,MAAD,CAAnB,GAA8B,IAA9B;AACD,CAHM;AAKP,OAAO,MAAMC,OAAO,GAAG,CAACN,KAAD,EAAgBO,IAAhB,KAA8B;AACnD,QAAMC,GAAG,GAAG;AAAEC,IAAAA,OAAO,EAAEF;AAAX,GAAZ;AACAd,EAAAA,gBAAgB,CAACa,OAAjB,CAAyBN,KAAzB,EAAgCQ,GAAhC;AACD,CAHM;AAKP,OAAO,MAAME,QAAQ,GAAIC,GAAD,IAAiB;AACvCjB,EAAAA,gBAAgB,CAACgB,QAAjB,CAA0BC,GAA1B;AACD,CAFM;AAYP,OAAO,MAAMC,SAAS,GAAIC,MAAD,IAAoB;AAC3CnB,EAAAA,gBAAgB,CAACkB,SAAjB,CAA2BC,MAA3B;AACD,CAFM","sourcesContent":["import { NativeEventEmitter, NativeModules, ViewProps } from 'react-native';\n\nconst { IONPortalsPubSub, IONPortalManager } = NativeModules;\n\nexport { default as PortalView } from './PortalView';\n\nexport interface Message {\n subscriptionRef: number;\n data: any;\n topic: string;\n}\n\nconst PortalsPubSub = new NativeEventEmitter(IONPortalsPubSub);\n\nlet subscriptionRefDict: any = {};\n\nexport const subscribe = async (\n topic: string,\n onMessageReceived: (message: Message) => void\n): Promise<number> => {\n const subscriptionRef = await IONPortalsPubSub.subscribe(topic);\n subscriptionRefDict[subscriptionRef] = PortalsPubSub.addListener(\n 'PortalsSubscription',\n onMessageReceived\n );\n return subscriptionRef;\n};\n\nexport const unsubscribe = (topic: string, subRef: number) => {\n IONPortalsPubSub.unsubscribe(topic, subRef);\n subscriptionRefDict[subRef] = null;\n};\n\nexport const publish = (topic: string, data: any) => {\n const msg = { message: data };\n IONPortalsPubSub.publish(topic, msg);\n};\n\nexport const register = (key: string) => {\n IONPortalManager.register(key);\n};\n\nexport interface Portal {\n name: string;\n startDir?: string;\n initialContext?: any;\n}\n\nexport type PortalProps = Pick<Portal, 'name' | 'initialContext'> & ViewProps;\n\nexport const addPortal = (portal: Portal) => {\n IONPortalManager.addPortal(portal);\n};\n"]}
1
+ {"version":3,"names":["NativeEventEmitter","NativeModules","IONPortalPubSub","IONPortalManager","IONLiveUpdatesManager","default","PortalView","PortalsPubSub","subscriptionMap","Map","subscribe","topic","onMessageReceived","subscriptionRef","subscriber","addListener","message","set","unsubscribe","subRef","subscription","get","undefined","remove","delete","publish","data","msg","register","key","addPortal","portal","syncOne","appId","syncSome","appIds","syncAll"],"sources":["index.ts"],"sourcesContent":["import {\n EmitterSubscription,\n NativeEventEmitter,\n NativeModules,\n ViewProps,\n} from 'react-native';\n\nconst { IONPortalPubSub, IONPortalManager, IONLiveUpdatesManager } =\n NativeModules;\n\nexport { default as PortalView } from './PortalView';\n\nexport interface Message {\n subscriptionRef: number;\n data: any;\n topic: string;\n}\n\nconst PortalsPubSub = new NativeEventEmitter(IONPortalPubSub);\n\nconst subscriptionMap = new Map<number, EmitterSubscription>();\n\nexport const subscribe = async (\n topic: string,\n onMessageReceived: (message: Message) => void\n): Promise<number> => {\n const subscriptionRef = await IONPortalPubSub.subscribe(topic);\n\n const subscriber = PortalsPubSub.addListener(\n 'PortalsSubscription',\n (message: Message) => {\n if (message.subscriptionRef === subscriptionRef) {\n onMessageReceived(message);\n }\n }\n );\n\n subscriptionMap.set(subscriptionRef, subscriber);\n\n return subscriptionRef;\n};\n\nexport const unsubscribe = (topic: string, subRef: number) => {\n IONPortalPubSub.unsubscribe(topic, subRef);\n\n const subscription = subscriptionMap.get(subRef);\n if (subscription !== undefined) {\n subscription.remove();\n subscriptionMap.delete(subRef);\n }\n};\n\nexport const publish = (topic: string, data: any) => {\n const msg = { message: data };\n IONPortalPubSub.publish(topic, msg);\n};\n\nexport const register = (key: string) => {\n IONPortalManager.register(key);\n};\n\nexport interface Portal {\n name: string;\n androidPlugins?: string[];\n startDir?: string;\n initialContext?: {\n [key: string]: any;\n };\n liveUpdate?: LiveUpdateConfig;\n}\n\nexport type PortalProps = Pick<Portal, 'name' | 'initialContext'> & ViewProps;\n\nexport const addPortal = (portal: Portal) => {\n IONPortalManager.addPortal(portal);\n};\n\nexport interface LiveUpdate {\n appId: string;\n channel: string;\n}\n\nexport type LiveUpdateConfig = LiveUpdate & { syncOnAdd: boolean };\n\nexport interface LiveUpdateError {\n appId: string;\n failStep: string;\n message: string;\n}\n\nexport interface SyncResults {\n liveUpdates: LiveUpdate[];\n errors: LiveUpdateError[];\n}\n\nexport const syncOne = (appId: string): Promise<LiveUpdate> => {\n return IONLiveUpdatesManager.syncOne(appId);\n};\n\nexport const syncSome = (appIds: string[]): Promise<SyncResults> => {\n return IONLiveUpdatesManager.syncSome(appIds);\n};\n\nexport const syncAll = (): Promise<SyncResults> => {\n return IONLiveUpdatesManager.syncAll();\n};\n"],"mappings":"AAAA,SAEEA,kBAFF,EAGEC,aAHF,QAKO,cALP;AAOA,MAAM;EAAEC,eAAF;EAAmBC,gBAAnB;EAAqCC;AAArC,IACJH,aADF;AAGA,SAASI,OAAO,IAAIC,UAApB,QAAsC,cAAtC;AAQA,MAAMC,aAAa,GAAG,IAAIP,kBAAJ,CAAuBE,eAAvB,CAAtB;AAEA,MAAMM,eAAe,GAAG,IAAIC,GAAJ,EAAxB;AAEA,OAAO,MAAMC,SAAS,GAAG,OACvBC,KADuB,EAEvBC,iBAFuB,KAGH;EACpB,MAAMC,eAAe,GAAG,MAAMX,eAAe,CAACQ,SAAhB,CAA0BC,KAA1B,CAA9B;EAEA,MAAMG,UAAU,GAAGP,aAAa,CAACQ,WAAd,CACjB,qBADiB,EAEhBC,OAAD,IAAsB;IACpB,IAAIA,OAAO,CAACH,eAAR,KAA4BA,eAAhC,EAAiD;MAC/CD,iBAAiB,CAACI,OAAD,CAAjB;IACD;EACF,CANgB,CAAnB;EASAR,eAAe,CAACS,GAAhB,CAAoBJ,eAApB,EAAqCC,UAArC;EAEA,OAAOD,eAAP;AACD,CAlBM;AAoBP,OAAO,MAAMK,WAAW,GAAG,CAACP,KAAD,EAAgBQ,MAAhB,KAAmC;EAC5DjB,eAAe,CAACgB,WAAhB,CAA4BP,KAA5B,EAAmCQ,MAAnC;EAEA,MAAMC,YAAY,GAAGZ,eAAe,CAACa,GAAhB,CAAoBF,MAApB,CAArB;;EACA,IAAIC,YAAY,KAAKE,SAArB,EAAgC;IAC9BF,YAAY,CAACG,MAAb;IACAf,eAAe,CAACgB,MAAhB,CAAuBL,MAAvB;EACD;AACF,CARM;AAUP,OAAO,MAAMM,OAAO,GAAG,CAACd,KAAD,EAAgBe,IAAhB,KAA8B;EACnD,MAAMC,GAAG,GAAG;IAAEX,OAAO,EAAEU;EAAX,CAAZ;EACAxB,eAAe,CAACuB,OAAhB,CAAwBd,KAAxB,EAA+BgB,GAA/B;AACD,CAHM;AAKP,OAAO,MAAMC,QAAQ,GAAIC,GAAD,IAAiB;EACvC1B,gBAAgB,CAACyB,QAAjB,CAA0BC,GAA1B;AACD,CAFM;AAgBP,OAAO,MAAMC,SAAS,GAAIC,MAAD,IAAoB;EAC3C5B,gBAAgB,CAAC2B,SAAjB,CAA2BC,MAA3B;AACD,CAFM;AAsBP,OAAO,MAAMC,OAAO,GAAIC,KAAD,IAAwC;EAC7D,OAAO7B,qBAAqB,CAAC4B,OAAtB,CAA8BC,KAA9B,CAAP;AACD,CAFM;AAIP,OAAO,MAAMC,QAAQ,GAAIC,MAAD,IAA4C;EAClE,OAAO/B,qBAAqB,CAAC8B,QAAtB,CAA+BC,MAA/B,CAAP;AACD,CAFM;AAIP,OAAO,MAAMC,OAAO,GAAG,MAA4B;EACjD,OAAOhC,qBAAqB,CAACgC,OAAtB,EAAP;AACD,CAFM"}
@@ -11,8 +11,31 @@ export declare const publish: (topic: string, data: any) => void;
11
11
  export declare const register: (key: string) => void;
12
12
  export interface Portal {
13
13
  name: string;
14
+ androidPlugins?: string[];
14
15
  startDir?: string;
15
- initialContext?: any;
16
+ initialContext?: {
17
+ [key: string]: any;
18
+ };
19
+ liveUpdate?: LiveUpdateConfig;
16
20
  }
17
21
  export declare type PortalProps = Pick<Portal, 'name' | 'initialContext'> & ViewProps;
18
22
  export declare const addPortal: (portal: Portal) => void;
23
+ export interface LiveUpdate {
24
+ appId: string;
25
+ channel: string;
26
+ }
27
+ export declare type LiveUpdateConfig = LiveUpdate & {
28
+ syncOnAdd: boolean;
29
+ };
30
+ export interface LiveUpdateError {
31
+ appId: string;
32
+ failStep: string;
33
+ message: string;
34
+ }
35
+ export interface SyncResults {
36
+ liveUpdates: LiveUpdate[];
37
+ errors: LiveUpdateError[];
38
+ }
39
+ export declare const syncOne: (appId: string) => Promise<LiveUpdate>;
40
+ export declare const syncSome: (appIds: string[]) => Promise<SyncResults>;
41
+ export declare const syncAll: () => Promise<SyncResults>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ionic/portals-react-native",
3
- "version": "0.0.1",
3
+ "version": "0.0.4",
4
4
  "description": "Ionic Portals for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",