mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-19 16:57:40 +03:00
react: let user specify reconnectThreshold (#7566)
* react: let user specify reconnectThreshold Requested by a user on [the forum]. [the forum]: https://discuss.daml.com/t/usestreamquery-disconnecting/1325 CHANGELOG_BEGIN * JavaScript Client Libraries: Users of the React wrapper can now specify the `reconnectThreshold` parameter of the underlying Ledger through LedgerProps. This adds an optional attribute to the LedgerProps type, so existing code does not need any change to keep working as before (i.e. using the default 30s value). CHANGELOG_END * add test
This commit is contained in:
parent
c0aee099a1
commit
3bf0a82023
@ -30,6 +30,7 @@ const App: React.FC = () => {
|
|||||||
token: <your authentication token>
|
token: <your authentication token>
|
||||||
httpBaseUrl?: <optional http base url>
|
httpBaseUrl?: <optional http base url>
|
||||||
wsBaseUrl?: <optional websocket base url>
|
wsBaseUrl?: <optional websocket base url>
|
||||||
|
reconnectThreshold?: <optional delay in ms>
|
||||||
party: <the logged in party>
|
party: <the logged in party>
|
||||||
>
|
>
|
||||||
<MainScreen />
|
<MainScreen />
|
||||||
|
@ -23,6 +23,7 @@ export type LedgerProps = {
|
|||||||
httpBaseUrl?: string;
|
httpBaseUrl?: string;
|
||||||
wsBaseUrl?: string;
|
wsBaseUrl?: string;
|
||||||
party: Party;
|
party: Party;
|
||||||
|
reconnectThreshold?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,9 +87,9 @@ export function createLedgerContext(contextName="DamlLedgerContext"): LedgerCont
|
|||||||
// not make a new network request although they are required to refresh data.
|
// not make a new network request although they are required to refresh data.
|
||||||
|
|
||||||
const ledgerContext = React.createContext<DamlLedgerState | undefined>(undefined);
|
const ledgerContext = React.createContext<DamlLedgerState | undefined>(undefined);
|
||||||
const DamlLedger: React.FC<LedgerProps> = ({token, httpBaseUrl, wsBaseUrl, party, children}) => {
|
const DamlLedger: React.FC<LedgerProps> = ({token, httpBaseUrl, wsBaseUrl, reconnectThreshold, party, children}) => {
|
||||||
const [reloadToken, setReloadToken] = useState(0);
|
const [reloadToken, setReloadToken] = useState(0);
|
||||||
const ledger = useMemo(() => new Ledger({token, httpBaseUrl, wsBaseUrl}), [token, httpBaseUrl, wsBaseUrl]);
|
const ledger = useMemo(() => new Ledger({token, httpBaseUrl, wsBaseUrl, reconnectThreshold}), [token, httpBaseUrl, wsBaseUrl, reconnectThreshold]);
|
||||||
const state: DamlLedgerState = useMemo(() => ({
|
const state: DamlLedgerState = useMemo(() => ({
|
||||||
reloadToken,
|
reloadToken,
|
||||||
triggerReload: (): void => setReloadToken(x => x + 1),
|
triggerReload: (): void => setReloadToken(x => x + 1),
|
||||||
|
@ -69,7 +69,7 @@ const TOKEN = 'test_token';
|
|||||||
const PARTY = 'test_party';
|
const PARTY = 'test_party';
|
||||||
|
|
||||||
function renderDamlHook<P, R>(callback: (props: P) => R): RenderHookResult<P, R> {
|
function renderDamlHook<P, R>(callback: (props: P) => R): RenderHookResult<P, R> {
|
||||||
const wrapper: ComponentType = ({children}) => React.createElement(DamlLedger, {token: TOKEN, party: PARTY}, children);
|
const wrapper: ComponentType = ({children}) => React.createElement(DamlLedger, {token: TOKEN, party: PARTY, reconnectThreshold: 1337}, children);
|
||||||
return renderHook(callback, {wrapper});
|
return renderHook(callback, {wrapper});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ beforeEach(() => {
|
|||||||
test('DamlLedger', () => {
|
test('DamlLedger', () => {
|
||||||
renderDamlHook(() => { return; });
|
renderDamlHook(() => { return; });
|
||||||
expect(mockConstructor).toHaveBeenCalledTimes(1);
|
expect(mockConstructor).toHaveBeenCalledTimes(1);
|
||||||
expect(mockConstructor).toHaveBeenLastCalledWith({token: TOKEN, httpBaseUrl: undefined, wsBaseUrl: undefined});
|
expect(mockConstructor).toHaveBeenLastCalledWith({token: TOKEN, httpBaseUrl: undefined, wsBaseUrl: undefined, reconnectThreshold: 1337});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('useParty', () => {
|
test('useParty', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user