Allow PubSub to Use External Instance#828
Allow PubSub to Use External Instance#828KetanReddy wants to merge 9 commits intoplayer-1-dot-zerofrom
Conversation
Co-authored-by: Kelly Harrop <kn.harrop@gmail.com>
…ts (#827) * Add CLAUDE.md with guidelines for reporting and reviewing pull requests * Fix: Include CONTRIBUTORS in Claude Code Review job conditions
* Cancels the already-running scroll animation on page transition
Bundle ReportChanges will increase total bundle size by 9.24kB (0.16%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: plugins/reference-assets/coreAssets Changed:
view changes for bundle: core/playerAssets Changed:
view changes for bundle: plugins/auto-scroll/reactAssets Changed:
view changes for bundle: plugins/metrics/coreAssets Changed:
view changes for bundle: core/partial-match-registryAssets Changed:
view changes for bundle: plugins/markdown/coreAssets Changed:
view changes for bundle: plugins/async-node/coreAssets Changed:
view changes for bundle: plugins/stage-revert-data/coreAssets Changed:
view changes for bundle: plugins/common-types/coreAssets Changed:
view changes for bundle: plugins/check-path/coreAssets Changed:
view changes for bundle: react/playerAssets Changed:
view changes for bundle: plugins/common-expressions/coreAssets Changed:
view changes for bundle: plugins/beacon/coreAssets Changed:
view changes for bundle: plugins/pubsub/coreAssets Changed:
|
| /** | ||
| The JS context in which this TinyPubSub instance lives. | ||
| Setting this property loads the PubSubPlugin native bundle (if not already loaded) and | ||
| constructs the JS TinyPubSub instance. Subsequent assignments are ignored once the instance | ||
| has been created. | ||
| */ | ||
| public var context: JSContext? { | ||
| didSet { | ||
| guard let jsContext = context, jsValue == nil else { return } | ||
| if let url = ResourceUtilities.urlForFile(name: "PubSubPlugin.native", ext: "js", bundle: Bundle.module), | ||
| let jsString = try? String(contentsOf: url, encoding: .utf8) { | ||
| jsContext.evaluateScript(jsString) | ||
| } | ||
| jsValue = jsContext.evaluateScript("new PubSubPlugin.TinyPubSub()") | ||
| } | ||
| } |
There was a problem hiding this comment.
Can this be moved to the init? Since this is only supposed to happen once, re: "Subsequent assignments are ignored once the instance has been created.", the init seems like the more appropriate place for this to live. Using didSet like this is strange and will confuse users, imo.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## player-1-dot-zero #828 +/- ##
====================================================
- Coverage 85.90% 0 -85.91%
====================================================
Files 507 0 -507
Lines 22891 0 -22891
Branches 2656 0 -2656
====================================================
- Hits 19664 0 -19664
+ Misses 2898 0 -2898
+ Partials 329 0 -329 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| * sharedBus.subscribe("myEvent") { event, data -> /* ... */ } | ||
| * ``` | ||
| */ | ||
| public class TinyPubSub { |
There was a problem hiding this comment.
Why do we need this exposed for mobile?
There was a problem hiding this comment.
If you wanted to instantiate your own pubsub to pass it in, wouldn't you need a native way to create that object?
| val pubSubVarName = sharedPubSub?.getOrCreate(runtime) | ||
|
|
||
| instance = when { | ||
| pubSubVarName != null && config != null -> { | ||
| runtime.add("pubsubConfig", config) | ||
| runtime.buildInstance("(new $name({...pubsubConfig, pubsub: $pubSubVarName}))") | ||
| } | ||
| pubSubVarName != null -> | ||
| runtime.buildInstance("(new $name({pubsub: $pubSubVarName}))") | ||
| config != null -> { | ||
| runtime.add("pubsubConfig", config) | ||
| runtime.buildInstance("(new $name(pubsubConfig))") | ||
| } | ||
| else -> runtime.buildInstance() | ||
| } |
There was a problem hiding this comment.
I think the TS layer should handle creating the TS things it needs if we don't pass it in. We should interface with as little core internals as possible for the mobile wrappers.
Closes #785
Change Type (required)
Indicate the type of change your pull request is:
patchminormajorN/ADoes your PR have any documentation updates?