global-input-react
Advanced tools
Comparing version 4.2.1 to 4.2.2
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.displayQRCode = exports.qrCodeLabel = exports.loading = exports.reducer = exports.startConnect = exports.sendInitData = exports.initDataIdentity = exports.isValidInitData = exports.sendValue = exports.disconnect = exports.initialState = void 0; | ||
exports.displayQRCode = exports.qrCodeLabel = exports.loading = exports.reducer = exports.startConnect = exports.sendInitData = exports.isValidInitData = exports.sendValue = exports.disconnect = exports.initialState = void 0; | ||
@@ -116,12 +116,2 @@ var _react = _interopRequireWildcard(require("react")); | ||
const initDataIdentity = initData => { | ||
if (!isValidInitData(initData)) { | ||
return ''; | ||
} | ||
return initData.id + "/" + initData.form.id; | ||
}; | ||
exports.initDataIdentity = initDataIdentity; | ||
const buildMessageHandlersForInitData = (initData, notify) => { | ||
@@ -241,2 +231,3 @@ const fields = []; | ||
mobileData.client = client; | ||
options && options.onSenderConnected && options.onSenderConnected(client, clients); | ||
notify({ | ||
@@ -249,6 +240,12 @@ type: ACTION_TYPES.SENDER_CONNECTED | ||
mobileData.client = client; | ||
closeConnection(); | ||
mobileData.mobileState = MobileState.INITIALIZING; | ||
mobileData.session = (0, _globalInputMessage.createMessageConnector)(); | ||
mobileData.session.connect(mobileData.mobileConfig); | ||
if (clients && clients.length) { | ||
console.log("-multi-client-"); | ||
} else { | ||
mobileData.mobileState = MobileState.INITIALIZING; | ||
mobileData.session.connect(mobileData.mobileConfig); | ||
console.log("-client-disconnected-"); | ||
} | ||
options && options.onSenderDisconnected && options.onSenderDisconnected(client, clients); | ||
notify({ | ||
@@ -292,3 +289,8 @@ type: ACTION_TYPES.SENDER_DISCONNECTED | ||
const startConnect = (notify, initDataConfigured, options) => { | ||
const startConnect = (config, configId, notify) => { | ||
if (!isValidInitData(config.initData)) { | ||
console.log(" init-data-use-empty-" + configId); | ||
return; | ||
} | ||
const { | ||
@@ -299,4 +301,4 @@ setters, | ||
initData | ||
} = buildMessageHandlersForInitData(initDataConfigured, notify); | ||
mobileData.mobileConfig = buildMobileConfig(initData, options, notify); | ||
} = buildMessageHandlersForInitData(config.initData, notify); | ||
mobileData.mobileConfig = buildMobileConfig(initData, config.options, notify); | ||
setFieldProperties(fields, values, setters); | ||
@@ -312,5 +314,8 @@ | ||
closeConnection(); | ||
mobileData.mobileState = MobileState.INITIALIZING; | ||
mobileData.session = (0, _globalInputMessage.createMessageConnector)(); | ||
if (!mobileData.session) { | ||
mobileData.session = (0, _globalInputMessage.createMessageConnector)(); | ||
} | ||
mobileData.session.connect(mobileData.mobileConfig); | ||
@@ -317,0 +322,0 @@ notify({ |
@@ -57,2 +57,9 @@ "use strict"; | ||
(0, _react.useEffect)(() => { | ||
attached.current = true; | ||
return () => { | ||
attached.current = false; | ||
}; | ||
}, []); | ||
if (typeof config === 'function') { | ||
@@ -62,31 +69,21 @@ config = config(); | ||
let intDataConfigured = null; | ||
if (config) { | ||
intDataConfigured = config.initData; | ||
if (typeof intDataConfigured === 'function') { | ||
intDataConfigured = intDataConfigured(); | ||
} | ||
if (typeof config.initData === 'function') { | ||
config.initData = config.initData(); | ||
} | ||
const initDataIdentity = globalInput.initDataIdentity(intDataConfigured); | ||
const initDataRef = (0, _react.useRef)(null); | ||
initDataRef.current = intDataConfigured; | ||
const optionsRef = (0, _react.useRef)(null); | ||
optionsRef.current = config && config.option; | ||
const configRef = (0, _react.useRef)(config); | ||
configRef.current = config; | ||
const configId = config.initData && config.initData.id ? config.initData.id : ''; | ||
(0, _react.useEffect)(() => { | ||
attached.current = true; | ||
globalInput.startConnect(configRef.current, configId, notify); | ||
}, [configId]); //You don't need to memoize the input parameter of this hook. | ||
if (!globalInput.isValidInitData(initDataRef.current)) { | ||
console.log(" init-data-use-empty "); | ||
const restart = (0, _react.useCallback)(config => { | ||
if (!attached.current) { | ||
return; | ||
} | ||
globalInput.startConnect(notify, initDataRef.current, optionsRef.current); | ||
return () => { | ||
attached.current = false; | ||
}; | ||
}, [initDataIdentity]); //only execute once the identity is changed to allow the application to use simple construct to create parameter. | ||
globalInput.disconnect(notify); | ||
globalInput.startConnect(config ? config : configRef.current, configId, notify); | ||
}, [configId]); | ||
const sendInitData = (0, _react.useCallback)(initData => { | ||
@@ -160,4 +157,5 @@ if (!attached.current) { | ||
sendInitData, | ||
setOnchange, | ||
disconnect, | ||
setOnchange | ||
restart | ||
}; | ||
@@ -164,0 +162,0 @@ }; |
@@ -32,7 +32,7 @@ import React from 'react'; | ||
level?: "L" | "M" | "Q" | "H", | ||
label?:React.ReactNode, | ||
loading?:React.ReactNode, | ||
maxSize?:number; | ||
marginTop?:number; | ||
marginLeft?:number; | ||
label?: React.ReactNode, | ||
loading?: React.ReactNode, | ||
maxSize?: number; | ||
marginTop?: number; | ||
marginLeft?: number; | ||
}; | ||
@@ -54,2 +54,3 @@ export interface GlobalInputData { | ||
disconnect: () => void; | ||
restart: (config?: ConfigData) => void; | ||
} | ||
@@ -56,0 +57,0 @@ |
{ | ||
"name": "global-input-react", | ||
"version": "4.2.1", | ||
"version": "4.2.2", | ||
"description": "global input react component", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index", |
@@ -95,9 +95,2 @@ | ||
export const initDataIdentity = (initData) => { | ||
if (!isValidInitData(initData)) { | ||
return ''; | ||
} | ||
return initData.id + "/" + initData.form.id; | ||
} | ||
const buildMessageHandlersForInitData = (initData, notify) => { | ||
@@ -195,2 +188,3 @@ | ||
mobileData.client = client; | ||
options && options.onSenderConnected && options.onSenderConnected(client, clients); | ||
notify({ type: ACTION_TYPES.SENDER_CONNECTED }); | ||
@@ -201,7 +195,13 @@ }, | ||
mobileData.client = client; | ||
closeConnection(); | ||
mobileData.mobileState = MobileState.INITIALIZING; | ||
mobileData.session = createMessageConnector(); | ||
mobileData.session.connect(mobileData.mobileConfig); | ||
if (clients && clients.length) { | ||
console.log("-multi-client-"); | ||
} | ||
else { | ||
mobileData.mobileState = MobileState.INITIALIZING; | ||
mobileData.session.connect(mobileData.mobileConfig); | ||
console.log("-client-disconnected-"); | ||
} | ||
options && options.onSenderDisconnected && options.onSenderDisconnected(client, clients); | ||
notify({ type: ACTION_TYPES.SENDER_DISCONNECTED }); | ||
}, | ||
@@ -231,5 +231,9 @@ onError: errorMessage => { | ||
export const startConnect = (notify, initDataConfigured, options) => { | ||
const { setters, fields, values, initData } = buildMessageHandlersForInitData(initDataConfigured, notify); | ||
mobileData.mobileConfig = buildMobileConfig(initData, options, notify); | ||
export const startConnect = (config, configId, notify) => { | ||
if (!isValidInitData(config.initData)) { | ||
console.log(" init-data-use-empty-" + configId); | ||
return; | ||
} | ||
const { setters, fields, values, initData } = buildMessageHandlersForInitData(config.initData, notify); | ||
mobileData.mobileConfig = buildMobileConfig(initData, config.options, notify); | ||
setFieldProperties(fields, values, setters); | ||
@@ -241,5 +245,6 @@ if (mobileData.mobileState === MobileState.MOBILE_CONNECTED) { | ||
} | ||
closeConnection(); | ||
mobileData.mobileState = MobileState.INITIALIZING; | ||
mobileData.session = createMessageConnector(); | ||
if (!mobileData.session) { | ||
mobileData.session = createMessageConnector(); | ||
} | ||
mobileData.session.connect(mobileData.mobileConfig); | ||
@@ -246,0 +251,0 @@ notify({ type: ACTION_TYPES.START_CONNECT }); |
@@ -27,2 +27,8 @@ | ||
}; | ||
useEffect(() => { | ||
attached.current = true; | ||
return () => { | ||
attached.current = false; | ||
} | ||
}, []); | ||
@@ -32,27 +38,22 @@ if (typeof config === 'function') { | ||
} | ||
let intDataConfigured = null; | ||
if (config) { | ||
intDataConfigured = config.initData; | ||
if (typeof intDataConfigured === 'function') { | ||
intDataConfigured = intDataConfigured(); | ||
} | ||
if (typeof config.initData === 'function') { | ||
config.initData = config.initData(); | ||
} | ||
const initDataIdentity = globalInput.initDataIdentity(intDataConfigured); | ||
const initDataRef = useRef(null); | ||
initDataRef.current = intDataConfigured; | ||
const optionsRef = useRef(null); | ||
optionsRef.current = config && config.option; | ||
const configRef = useRef(config); | ||
configRef.current = config; | ||
const configId = config.initData && config.initData.id ? config.initData.id : ''; | ||
useEffect(() => { | ||
attached.current = true; | ||
if (!globalInput.isValidInitData(initDataRef.current)) { | ||
console.log(" init-data-use-empty "); | ||
globalInput.startConnect(configRef.current, configId, notify); | ||
}, [configId]); //You don't need to memoize the input parameter of this hook. | ||
const restart = useCallback((config) => { | ||
if (!attached.current) { | ||
return; | ||
} | ||
globalInput.startConnect(notify, initDataRef.current, optionsRef.current); | ||
return () => { | ||
attached.current = false; | ||
} | ||
}, [initDataIdentity]); //only execute once the identity is changed to allow the application to use simple construct to create parameter. | ||
globalInput.disconnect(notify); | ||
globalInput.startConnect(config ? config : configRef.current, configId, notify); | ||
}, [configId]) | ||
const sendInitData = useCallback((initData) => { | ||
@@ -76,2 +77,4 @@ if (!attached.current) { | ||
}, []); | ||
const sendValue = globalInput.sendValue; | ||
@@ -120,5 +123,6 @@ | ||
sendInitData, | ||
setOnchange, | ||
disconnect, | ||
setOnchange, | ||
restart, | ||
}; | ||
}; |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1245999
37257