@adcops/autocore-react 3.0.13 → 3.0.14
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
2
|
import { Hub } from "../hub";
|
|
3
|
+
import { CommandMessageResult } from "../hub/CommandMessage";
|
|
3
4
|
export { Hub };
|
|
4
5
|
/**
|
|
5
6
|
* Represents an event subsription.
|
|
@@ -76,7 +77,7 @@ export interface EventEmitterContextType {
|
|
|
76
77
|
* Invoke/send a message to the back end.
|
|
77
78
|
* This does NOT get published to the front end.
|
|
78
79
|
*/
|
|
79
|
-
invoke(domain: string, fname: string, payload?: object): Promise<
|
|
80
|
+
invoke(domain: string, fname: string, payload?: object): Promise<CommandMessageResult>;
|
|
80
81
|
/**
|
|
81
82
|
* Subscribe to events identified by the topic.
|
|
82
83
|
* @param topic The subscription topic.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{createContext,useState,useMemo}from"react";import{createHub,Hub}from"../hub";export{Hub};let globalSubscriptionId=1;export const EventEmitterContext=createContext({state:{subscriptions:{},nextSubscriptionId:1},dispatch:()=>{},subscribe:()=>0,invoke:async(t,s,e)=>Promise.resolve({}),unsubscribe:t=>{},hub:null,getSubscriptions:()=>[]});export const EventEmitterProvider=({children:t})=>{const[s,e]=useState({subscriptions:{},nextSubscriptionId:1}),i=useMemo((()=>createHub()),[]),r=t=>{const{topic:s,payload:i}=t;e((t=>(t.subscriptions[s]?.forEach((t=>t.callback(i))),{...t,eventData:i})))},o=(t,s)=>{globalSubscriptionId+=1;const i=globalSubscriptionId;return e((e=>({...e,subscriptions:{...e.subscriptions,[t]:[...e.subscriptions[t]||[],{id:i,callback:s}]},nextSubscriptionId:globalSubscriptionId+1}))),i},n=t=>{e((s=>{const e={...s.subscriptions};for(const s in e)e.hasOwnProperty(s)&&(e[s]=e[s].filter((s=>s.id!==t)),0===e[s].length&&delete e[s]);return{...s,subscriptions:e}}))},c=t=>t?s.subscriptions[t]||[]:s.subscriptions,u=useMemo((()=>({state:s,dispatch:r,subscribe:o,unsubscribe:n,invoke:i.invoke,hub:i,getSubscriptions:c})),[s,i]);return i.setContext(u),_jsx(EventEmitterContext.Provider,{value:u,children:t})};
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{createContext,useState,useMemo}from"react";import{createHub,Hub}from"../hub";export{Hub};let globalSubscriptionId=1;export const EventEmitterContext=createContext({state:{subscriptions:{},nextSubscriptionId:1},dispatch:()=>{},subscribe:()=>0,invoke:async(t,s,e)=>Promise.resolve({data:{},success:!1,error_message:""}),unsubscribe:t=>{},hub:null,getSubscriptions:()=>[]});export const EventEmitterProvider=({children:t})=>{const[s,e]=useState({subscriptions:{},nextSubscriptionId:1}),i=useMemo((()=>createHub()),[]),r=t=>{const{topic:s,payload:i}=t;e((t=>(t.subscriptions[s]?.forEach((t=>t.callback(i))),{...t,eventData:i})))},o=(t,s)=>{globalSubscriptionId+=1;const i=globalSubscriptionId;return e((e=>({...e,subscriptions:{...e.subscriptions,[t]:[...e.subscriptions[t]||[],{id:i,callback:s}]},nextSubscriptionId:globalSubscriptionId+1}))),i},n=t=>{e((s=>{const e={...s.subscriptions};for(const s in e)e.hasOwnProperty(s)&&(e[s]=e[s].filter((s=>s.id!==t)),0===e[s].length&&delete e[s]);return{...s,subscriptions:e}}))},c=t=>t?s.subscriptions[t]||[]:s.subscriptions,u=useMemo((()=>({state:s,dispatch:r,subscribe:o,unsubscribe:n,invoke:i.invoke,hub:i,getSubscriptions:c})),[s,i]);return i.setContext(u),_jsx(EventEmitterContext.Provider,{value:u,children:t})};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (C) 2024 Automated Design Corp. All Rights Reserved.
|
|
3
3
|
* Created Date: 2024-01-17 11:45:10
|
|
4
4
|
* -----
|
|
5
|
-
* Last Modified: 2024-04-
|
|
5
|
+
* Last Modified: 2024-04-24 12:11:16
|
|
6
6
|
* Modified By: ADC
|
|
7
7
|
* -----
|
|
8
8
|
*
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
import React, { createContext, ReactNode, useState, useMemo } from 'react';
|
|
13
13
|
import {createHub, Hub} from "../hub";
|
|
14
|
+
import {CommandMessageResult} from "../hub/CommandMessage";
|
|
14
15
|
|
|
15
16
|
export {Hub};
|
|
16
17
|
|
|
@@ -103,7 +104,7 @@ export interface EventEmitterContextType {
|
|
|
103
104
|
* Invoke/send a message to the back end.
|
|
104
105
|
* This does NOT get published to the front end.
|
|
105
106
|
*/
|
|
106
|
-
invoke( domain: string, fname: string, payload? : object) : Promise<
|
|
107
|
+
invoke( domain: string, fname: string, payload? : object) : Promise<CommandMessageResult>;
|
|
107
108
|
|
|
108
109
|
/**
|
|
109
110
|
* Subscribe to events identified by the topic.
|
|
@@ -268,9 +269,14 @@ export const EventEmitterContext = createContext<EventEmitterContextType>({
|
|
|
268
269
|
domain;
|
|
269
270
|
fname;
|
|
270
271
|
payload;
|
|
272
|
+
let ret :CommandMessageResult = {
|
|
273
|
+
data: {},
|
|
274
|
+
success: false,
|
|
275
|
+
error_message : ""
|
|
276
|
+
};
|
|
271
277
|
// Placeholder for invoke logic
|
|
272
278
|
// Implement the logic to send a message to the backend and return a promise
|
|
273
|
-
return Promise.resolve(
|
|
279
|
+
return Promise.resolve(ret); // Example placeholder, replace with actual implementation
|
|
274
280
|
},
|
|
275
281
|
unsubscribe: (subscriptionId: number) => { subscriptionId;}, // Placeholder for unsubscription logic
|
|
276
282
|
hub: null,
|