@trakit/react 0.0.1 → 0.0.2
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/README.md +11 -3
- package/index.d.ts +1 -1
- package/package.json +5 -4
- package/trakit-react.min.js +2 -2
package/README.md
CHANGED
|
@@ -4,17 +4,25 @@ This library contains ReactJS controls, hooks, and contexts to assist in working
|
|
|
4
4
|
|
|
5
5
|
### Prerequisites
|
|
6
6
|
|
|
7
|
-
The `@trakit/objects` and `@trakit/
|
|
7
|
+
The `@trakit/objects`, `@trakit/commands` and `@trakit/sync` packages are required since they contain the definitions for all the commands required to manipulate the objects.
|
|
8
8
|
|
|
9
|
-
In order to build this project, you need to install the RollupJS, and plugins for TypeScript and Minifying.
|
|
9
|
+
In order to build this project, you need to install the ReactJS types, RollupJS, and plugins for TypeScript and Minifying.
|
|
10
10
|
```
|
|
11
|
-
npm i rollup rollup-plugin-typescript2 @rollup/plugin-terser
|
|
11
|
+
npm i @types/react rollup rollup-plugin-typescript2 @rollup/plugin-terser
|
|
12
12
|
```
|
|
13
13
|
After those have been installed, build the project normally.
|
|
14
14
|
```
|
|
15
15
|
rollup --config rollup.config.js
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
### `useConnection` hook
|
|
19
|
+
|
|
20
|
+
Used as the main hook for keeping a persistent connection.
|
|
21
|
+
|
|
22
|
+
### `useSync` hook
|
|
23
|
+
|
|
24
|
+
Used to synchronize the specified type(s) of objects with the system. Internally, this hook uses `useConnection`.
|
|
25
|
+
|
|
18
26
|
## Questions and Feedback
|
|
19
27
|
|
|
20
28
|
If you have any questions, please start for the project on GitHub
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trakit/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.2",
|
|
5
5
|
"main": "./trakit-react.min.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
7
7
|
"scripts": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"url": "https://github.com/trakitwireless/trakit-ts-react/issues"
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/trakitwireless/trakit-ts-react#readme",
|
|
29
|
-
"description": "
|
|
29
|
+
"description": "ReactJS controls, hooks, and contexts to assist in working with Trak-iT's APIs.",
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@rollup/plugin-terser": "^1.0.0",
|
|
32
32
|
"rollup": "^4.35.0",
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@trakit/commands": "^0.1.2",
|
|
39
39
|
"@trakit/objects": "^0.1.2",
|
|
40
|
-
"@trakit/sync": "^0.1.
|
|
41
|
-
"@types/react": "^19.2.17"
|
|
40
|
+
"@trakit/sync": "^0.1.2",
|
|
41
|
+
"@types/react": "^19.2.17",
|
|
42
|
+
"react-cookie": "^8.1.2"
|
|
42
43
|
}
|
|
43
44
|
}
|
package/trakit-react.min.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
function n(n,
|
|
1
|
+
function n(n,e){function t(n){I(n.online)}function o(n){const{account:e}=n;e.user?.login&&e.expiry>new Date?(u(y,e.ghostId,{...k,expires:e.expiry}),D(e.ghostId||"")):m(y,k),z(e.user||null),e.machine?.key&&e.expiry>new Date?(u(h,e.machine.key,{...k,expires:e.expiry}),u(g,e.machine.secret,{...k,expires:e.expiry})):(m(h,k),m(g,k)),S(e.machine||null)}const i=f(new s(null,n||l.URI_PROD,e||a.URI_PROD)),[r,u,m]=w([y,h,g]),[x,I]=d(i.current.socketOnline),[b,D]=d(r[y]||""),[j,z]=d(i.current.account.user||null),[N,S]=d(i.current.account.machine||r[h]&&new c({key:r[h],secret:r[g]})||null),v=x===!(!b&&!N);return p(()=>(i.current.on("open",t),i.current.on("error",t),i.current.on("close",t),i.current.on("account",o),(b||N)&&i.current.setAuth({ghostId:b,machine:N?.toJSON()}),()=>i.current.dispose()),[]),{synchronizer:i.current,ready:v,ghostId:b,online:x,user:j,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 m(e,t,o)}function r(e,t){const o=f(null),i=f(0),[r,c]=d(null),[s,l]=d(null),{synchronizer:m,ready:w,online:y,user:h,machine:g}=n();return p(()=>{function n(n,o){0!==i.current&&t===o&&e===n&&l([...u[n].values().filter(n=>n.companyId===t)])}function s(e){const{kind:t,companyId:o}=e;n(t,o)}function f(e){const{name:t,body:o}=e;n(a.msgNameToSyncName(t),o.company)}function d(){if(0===i.current){const n=r?.map(n=>n.syncName).filter(n=>!!n);n?.length&&m.desync(t,n),m.off("list",s),m.off("update",s),m.off("delete",s),m.off("message",f)}o.current=null}function p(o){c(o),n(e,t)}if(w&&e&&!isNaN(t))return i.current++,m.on("list",s),m.on("update",s),m.on("delete",s),m.on("message",f),o.current=m.sync(t,[e]),o.current.then(p,p),o.current.finally(d),()=>{i.current--,o.current||d()}},[w,y,t=t??h?.companyId??g?.companyId,e]),{ready:w&&y&&!!s&&!o.current,replies:r??[],objects:s??[]}}
|
|
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{
|
|
7
|
+
*/import{Machine as c,storage as u}from"@trakit/objects";import{TrakitSyncCommander as s,TrakitRestfulCommander as l,TrakitSocketCommander as a}from"@trakit/sync";import{useRef as f,useState as d,useEffect as p,useSyncExternalStore as m}from"react";import{useCookies as w}from"react-cookie";const y="ghostId",h="apiKey",g="apiSec",k={path:"/",secure:!0,sameSite:"strict",expires:new Date(0)},x="0.0.2";export{n as useConnection,i as useIsOnline,r as useSync,x as version};
|