@trakit/react 0.0.2 → 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.
- package/hooks/useConnection.d.ts +1 -1
- package/hooks/useSync.d.ts +34 -11
- package/index.d.ts +4 -4
- package/package.json +1 -1
- package/trakit-react.min.js +2 -2
package/hooks/useConnection.d.ts
CHANGED
|
@@ -37,5 +37,5 @@ export type UseConnectionResult = {
|
|
|
37
37
|
* It initializes the synchronizer, listens for connection and account events,
|
|
38
38
|
* and provides the current connection state and user/machine information.
|
|
39
39
|
*/
|
|
40
|
-
export
|
|
40
|
+
export declare function useConnection(restAddress?: URL | url | nothing, socketAddress?: URL | url | nothing): UseConnectionResult;
|
|
41
41
|
//# sourceMappingURL=useConnection.d.ts.map
|
package/hooks/useSync.d.ts
CHANGED
|
@@ -1,31 +1,54 @@
|
|
|
1
1
|
import { Reply } from '@trakit/commands';
|
|
2
2
|
import { IBelongCompany, IRequestable, nothing, SyncName, ulong } from '@trakit/objects';
|
|
3
3
|
/**
|
|
4
|
-
* The result of the `useSync` hook.
|
|
4
|
+
* The result of the `useSync` hook and `useSingle` hook.
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export interface UseSyncResult {
|
|
7
7
|
/**
|
|
8
|
-
* Whether the hook is currently loading data. This will be `true` until the initial synchronization
|
|
8
|
+
* Whether the hook is currently loading data. This will be `true` until the initial synchronization
|
|
9
|
+
* is complete, and may briefly become `true` again if the connection is lost and re-established.
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
loading: boolean;
|
|
11
12
|
/**
|
|
12
13
|
* The list of replies received from the synchronization process.
|
|
13
14
|
* This is normally not needed, but can be useful for debugging or error handling,
|
|
14
15
|
* as it contains the {@link Reply} classes with {@link ErrorCode} and {@link ErrorDetail}.
|
|
15
16
|
*/
|
|
16
|
-
replies: Reply[];
|
|
17
|
+
replies: Reply[] | null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The result of the `useSync` hook.
|
|
21
|
+
* This object behaves like a dictionary, where the {@link UseSyncResult} properties are combined with
|
|
22
|
+
* the synchronized objects of type `T` for each requested types.
|
|
23
|
+
*/
|
|
24
|
+
export type UseSyncMultiple<T extends IRequestable & IBelongCompany> = UseSyncResult & {
|
|
25
|
+
[key in SyncName]?: T[] | nothing;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The result of the `useSingle` hook.
|
|
29
|
+
* This is a combination of the {@link UseSyncResult} and the synchronized objects of type `T`
|
|
30
|
+
* for the given type, which are stored in an array.
|
|
31
|
+
*/
|
|
32
|
+
export type UseSyncSingle<T extends IRequestable & IBelongCompany> = UseSyncResult & {
|
|
17
33
|
/**
|
|
18
|
-
* The list of synchronized objects of type
|
|
34
|
+
* The list of synchronized objects of the requested type.
|
|
19
35
|
*/
|
|
20
|
-
objects: T[];
|
|
36
|
+
objects: T[] | nothing;
|
|
21
37
|
};
|
|
22
38
|
/**
|
|
23
|
-
* Subscribes to the given sync types for the
|
|
24
|
-
*
|
|
25
|
-
*
|
|
39
|
+
* Subscribes to the given sync types for the given company, returning the live list of synchronized
|
|
40
|
+
* objects and re-rendering whenever any object, or part of that list changes.
|
|
41
|
+
* @param types The {@link SyncName} array to subscribe to.
|
|
42
|
+
* @param companyId Optional company ID to filter the synchronized objects. Default is your own company.
|
|
43
|
+
* @returns An object containing the loading state, the list of replies, and the list(s) of synchronized objects.
|
|
44
|
+
*/
|
|
45
|
+
export declare function useSync<T extends IRequestable & IBelongCompany>(types: SyncName[], companyId?: ulong | nothing): UseSyncMultiple<T>;
|
|
46
|
+
/**
|
|
47
|
+
* Subscribes to the given sync type for the given company, returning the live list of synchronized
|
|
48
|
+
* objects and re-rendering whenever any object, or part of that list changes.
|
|
26
49
|
* @param type The {@link SyncName} to subscribe to.
|
|
27
50
|
* @param companyId Optional company ID to filter the synchronized objects. Default is your own company.
|
|
28
51
|
* @returns An object containing the loading state, the list of replies, and the list of synchronized objects.
|
|
29
52
|
*/
|
|
30
|
-
export
|
|
53
|
+
export declare function useSingle<T extends IRequestable & IBelongCompany>(type: SyncName, companyId?: ulong | nothing): UseSyncSingle<T>;
|
|
31
54
|
//# sourceMappingURL=useSync.d.ts.map
|
package/index.d.ts
CHANGED
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
* Last updated on Thu June 11 2026 15:43:01
|
|
5
5
|
* @copyright Trak-iT Wireless Inc. 2026
|
|
6
6
|
*/
|
|
7
|
-
import useConnection,
|
|
7
|
+
import { useConnection, UseConnectionResult } from "./hooks/useConnection";
|
|
8
8
|
import useIsOnline from "./hooks/useIsOnline";
|
|
9
|
-
import useSync,
|
|
9
|
+
import { useSingle, useSync, UseSyncMultiple, UseSyncResult, UseSyncSingle } from "./hooks/useSync";
|
|
10
10
|
/**
|
|
11
11
|
* Version number for this release.
|
|
12
12
|
*/
|
|
13
|
-
export declare const version = "0.0.
|
|
13
|
+
export declare const version = "0.0.4";
|
|
14
14
|
/**
|
|
15
15
|
* Hooks
|
|
16
16
|
*/
|
|
17
|
-
export { useConnection, useIsOnline, useSync, type UseConnectionResult, type UseSyncResult };
|
|
17
|
+
export { useConnection, useIsOnline, useSingle, useSync, type UseConnectionResult, type UseSyncMultiple, type UseSyncResult, type UseSyncSingle };
|
|
18
18
|
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
package/trakit-react.min.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
function n(n,e){function t(n){
|
|
1
|
+
function n(n,e){function t(n){b(n.online)}function o(n){const{account:e}=n;e.user?.login&&e.expiry>new Date?(c(h,e.ghostId,{...x,expires:e.expiry}),j(e.ghostId||"")):u(h,x),z(e.user||null),e.machine?.key&&e.expiry>new Date?(c(y,e.machine.key,{...x,expires:e.expiry}),c(k,e.machine.secret,{...x,expires:e.expiry})):(u(y,x),u(k,x)),S(e.machine||null)}const i=d(new l(null,n||a.URI_PROD,e||f.URI_PROD)),[r,c,u]=g([h,y,k]),[w,b]=p(i.current.socketOnline),[I,j]=p(r[h]||""),[D,z]=p(i.current.account.user||null),[N,S]=p(i.current.account.machine||r[y]&&new s({key:r[y],secret:r[k]})||null),v=w===!(!I&&!N);return m(()=>(i.current.on("open",t),i.current.on("error",t),i.current.on("close",t),i.current.on("account",o),(I||N)&&i.current.setAuth({ghostId:I,machine:N?.toJSON()}),()=>i.current.dispose()),[]),{synchronizer:i.current,ready:v,ghostId:I,online:w,user:D,machine:N}}function e(n){return window.addEventListener("online",n),window.addEventListener("offline",n),()=>{window.removeEventListener("online",n),window.removeEventListener("offline",n)}}function t(){return navigator.onLine}function o(){return!0}function i(){return w(e,t,o)}function r(e,t){const o=d(null),i=d(0),[r,c]=p(null),[s,l]=p({}),{synchronizer:a,ready:w,online:g,user:h,machine:y}=n();return m(()=>{function n(n,o){0!==i.current&&t===o&&e.includes(n)&&l(e=>({...e,[n]:[...u[n].values().filter(n=>n.companyId===t)]}))}function s(e){const{kind:t,companyId:o}=e;n(t,o)}function d(e){const{name:t,body:o}=e;n(f.msgNameToSyncName(t),o.company)}function p(){if(0===i.current){const n=r?.map(n=>n.syncName).filter(n=>!!n);n?.length&&a.desync(t,n),a.off("list",s),a.off("update",s),a.off("delete",s),a.off("message",d)}o.current=null}function m(o){c(o),e.forEach(e=>n(e,t))}if(w&&e?.length&&!isNaN(t))return i.current++,a.on("list",s),a.on("update",s),a.on("delete",s),a.on("message",d),o.current=a.sync(t,e),o.current.then(m,m),o.current.finally(p),()=>{i.current--,o.current||p()}},[t=t??h?.companyId??y?.companyId,e.sort().join(",")]),{loading:!(w&&g&&Object.keys(s).length&&!o.current),replies:r??[],...s}}function c(n,e){const{loading:t,replies:o,[n]:i}=r([n],e);return{loading:t,replies:o,objects:i??[]}}
|
|
2
2
|
/**
|
|
3
3
|
* ReactJS library.
|
|
4
4
|
* {@link https://github.com/trakitwireless/trakit-ts-react|ReactJS controls.}
|
|
5
5
|
* Last updated on Thu June 11 2026 15:43:01
|
|
6
6
|
* @copyright Trak-iT Wireless Inc. 2026
|
|
7
|
-
*/import{Machine as
|
|
7
|
+
*/import{Machine as s,storage as u}from"@trakit/objects";import{TrakitSyncCommander as l,TrakitRestfulCommander as a,TrakitSocketCommander as f}from"@trakit/sync";import{useRef as d,useState as p,useEffect as m,useSyncExternalStore as w}from"react";import{useCookies as g}from"react-cookie";const h="ghostId",y="aK",k="aS",x={path:"/",secure:!0,sameSite:"strict",expires:new Date(0)},b="0.0.4";export{n as useConnection,i as useIsOnline,c as useSingle,r as useSync,b as version};
|