0.20240425.0 • Published 1 year ago

@ndmspc/react-ndmspc-core v0.20240425.0

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
1 year ago

@ndmspc/react-ndmspc-core

Made with create-react-library

NPM JavaScript Style Guide

Install

npm install --save @ndmspc/react-ndmspc-core

Usage

import React, { useEffect, useLayoutEffect, useState } from 'react'
import { version } from 'jsroot'

import {
  localStore,
  redirectStore,
  NdmSpcContext,
  executorStore,
  Distributor,
  broker,
  WebSocketStreamBroker
} from './lib'
import LocalStoreInfoExample from './components/LocalStoreInfoExample'
import RedirectExample from './components/RedirectExample'
import HttpExample from './components/HttpExample'
import ExecutorInfoExample from './components/ExecutorStoreExample'
import DistributorExample from './components/DistributorExample'
import HistogramFunctionsExample from './components/HistogramFunctionsExample'
import StreamBrokerExample from './components/StreamBrokerExample'
import WebSocketConnectForm from './components/WebSocketConnectForm'

let store = {
  local: localStore('localOne'),
  localSecond: localStore('localTwo'),
  zmq2wsUrl: localStore('zmq2wsUrl'),
  sharedUrl: localStore('sharedUrl'),
  redirect: redirectStore(),
  ws: {
    app: redirectStore(),
    ws: redirectStore()
  },
  http: redirectStore(),
  executor: executorStore('executor'),
  salsaDistributor: new Distributor('sls'),
  projDistributor: new Distributor('proj'),
  viewDistributor: new Distributor('view'),
  configDistributor: new Distributor('cnf')
}

broker.state = {
  counter: 0,
  click: '',
  dbClick: '',
  hover: ''
}

// add subjects to broker
broker.addDistributor(store.projDistributor)
broker.addDistributor(store.salsaDistributor)
broker.addDistributor(store.viewDistributor)
broker.addDistributor(store.configDistributor)

// add handlers for subjects
broker.addHandlerFunc('sls', (dataFromSalsa) => {
  console.log(`Started Job`)

  setTimeout(() => {
    console.log(`Job Finished`)
    const counter = broker.state.counter ? broker.state.counter : 1
    broker.state = { ...broker.state, counter: counter + 1 }
    store.configDistributor.sendInputData('incremented')
    return dataFromSalsa
  }, 5000)
})

broker.addHandlerFunc(
  'view',
  null,
  (dataFromBrowser) => {
    console.log(`NdmBatchSystemComponent: ${dataFromBrowser.data}`)
    if (dataFromBrowser.event === 'CONTEXT') {
      broker.state[dataFromBrowser.data.operation] =
        dataFromBrowser.data.projName
    }
  },
  null
)

broker.addHandlerFunc(
  'cnf',
  null,
  (dataFromConfig) => {
    console.log(`NdmBatchSystemComponent: ${dataFromConfig.data}`)
  },
  null
)

store.userFunctions = {
  onClick: (data) => {
    if (broker.state.click) {
      const newData = {
        binx: data.binx,
        biny: data.biny,
        projName: broker.state.click
      }
      store.projDistributor.sendInputData(newData)
    }
  },
  onHover: (data) => {
    if (data) {
      if (broker.state.hover) {
        const newData = {
          binx: data.binx,
          biny: data.biny,
          projName: broker.state.hover
        }
        store.projDistributor.sendInputData(newData)
      }
    }
  },
  onDbClick: (data) => {
    if (broker.state.dbClick) {
      const newData = {
        binx: data.binx,
        biny: data.biny,
        projName: broker.state.dbClick
      }
      store.projDistributor.sendInputData(newData)
    }
  }
}

const App = () => {
  return (
    <>
      {version && <h2>JSROOT Version: {version}</h2>}
      <NdmSpcContext.Provider
        value={{
          zmq2ws: WebSocketStreamBroker(),
          shared: WebSocketStreamBroker()
        }}
      >
        <WebSocketConnectForm store={store.zmq2wsUrl} wssb='zmq2ws'/>
        <StreamBrokerExample wssb='zmq2ws'/>
        <WebSocketConnectForm store={store.sharedUrl} wssb='shared'/>
        <StreamBrokerExample wssb='shared'/>
      </NdmSpcContext.Provider>
      
      <LocalStoreInfoExample store={store.local} delay='1000' />
      <LocalStoreInfoExample store={store.localSecond} delay='1500' />
      <ExecutorInfoExample store={store.executor} />
      <RedirectExample store={store.redirect} />
      <HttpExample store={store} />
      <DistributorExample store={store} />
      <HistogramFunctionsExample />
    </>
  )
}

export default App

License

MIT © ndmspc

0.20240425.0

1 year ago

0.20240325.0

1 year ago

0.20240307.0

1 year ago

0.20240305.1

1 year ago

0.20240305.0

1 year ago

0.20240214.0

1 year ago

0.20240215.0

1 year ago

0.20240215.1

1 year ago

0.20240201.0

1 year ago

0.20240130.0

1 year ago

0.20231212.1

2 years ago

0.20231211.0

2 years ago

0.20231212.0

2 years ago

0.20230920.0

2 years ago

0.20230303.0

2 years ago

0.20230325.0

2 years ago

0.20230303.1

2 years ago

0.20230320.0

2 years ago

0.20230301.0

2 years ago

0.20230227.0

2 years ago

0.20230227.1

2 years ago

0.20230223.0

2 years ago

0.20221219.0

2 years ago

0.20221212.0

3 years ago

0.20221219.5

2 years ago

0.20221219.6

2 years ago

0.20221219.7

2 years ago

0.20221219.1

2 years ago

0.20221219.2

2 years ago

0.20221219.3

2 years ago

0.20221219.4

2 years ago

0.20220621.0

3 years ago

0.20220621.1

3 years ago

0.20220613.1

3 years ago

0.20220613.0

3 years ago

0.20220502.1

3 years ago

0.20220523.0

3 years ago

0.20220427.1

3 years ago

0.20220326.1

3 years ago

0.20220211.1

3 years ago