-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
178 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
export { createUseIcepeak, createCoreUseIcepeak } | ||
|
||
import * as icepeak_core from './icepeak-core.mjs'; | ||
import * as icepeak from './icepeak.mjs'; | ||
|
||
import { useState, useEffect } from 'react'; | ||
|
||
function createUseIcepeak(icepeakObject : icepeak.Icepeak) { | ||
|
||
function useIcepeak(path : string) { | ||
const [ icepeakPathValue, setIcepeakPathValue ] | ||
= useState<unknown>(null); | ||
|
||
useEffect(() => { | ||
const subscription = icepeakObject | ||
.subscribe(path, setIcepeakPathValue) | ||
return () => subscription.unsubscribe() | ||
}) | ||
return icepeakPathValue | ||
} | ||
|
||
return useIcepeak | ||
} | ||
|
||
function createCoreUseIcepeak<TokenExtraData>( | ||
icepeakCoreObject : icepeak_core.IcepeakCore<any, TokenExtraData>, | ||
) { | ||
|
||
function useIcepeak(path : string, tokenExtraData : TokenExtraData) { | ||
const [ icepeakPathValue, setIcepeakPathValue ] | ||
= useState<unknown>(null); | ||
|
||
useEffect(() => { | ||
const subscriptionRef | ||
= icepeakCoreObject.createSubscriptionRef(path) | ||
|
||
subscriptionRef.onUpdate(setIcepeakPathValue) | ||
subscriptionRef.subscribe(tokenExtraData) | ||
|
||
return () => subscriptionRef.unusubscribe() | ||
}) | ||
return icepeakPathValue | ||
} | ||
|
||
return useIcepeak | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as test_util from "./test-util.mjs" | ||
import WebSocket from 'ws' | ||
|
||
import * as icepeak from "../lib/icepeak.mjs" | ||
import * as icepeak_core from "../lib/icepeak-core.mjs" | ||
|
||
test_util.fill_node_event_queue() | ||
test_util.handle_test_result(icepeakCoreTest()) | ||
|
||
|
||
async function icepeakCoreTest() { | ||
console.log("Starting Test") | ||
const config = { | ||
websocketUrl: "ws://localhost:3000/?method=reusable", | ||
websocketConstructor: (url: string) => new WebSocket(url), | ||
fetchTokenFn: test_util.fetch_dummy_token, | ||
calculateRetry: () => null, | ||
logger: test_util.log_everything | ||
}; | ||
|
||
await test_util.put_data({}, "") | ||
|
||
const w1 = new test_util.Wait() | ||
const w2 = new test_util.Wait() | ||
const icepeakCore = icepeak_core.createIcepeakCore(config); | ||
const s1 = icepeakCore.createSubscriptionRef("root/sub1") | ||
const s2 = icepeakCore.createSubscriptionRef("root") | ||
s2.onUpdate = u => {console.log("S2 updated:", u)} | ||
s2.subscribe(null) | ||
s1.onSuccess = _ => {console.log("S1 subscribed"); w1.done()} | ||
s1.onUpdate = u => {console.log("S1 updated:", u); w2.done()} | ||
s1.subscribe(null) | ||
await w1.wait | ||
test_util.put_data(3, "/root/sub1") | ||
await w2.wait | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.