Skip to content

Commit 1b40bb6

Browse files
committed
sending value also refresh state
1 parent 909ed5b commit 1b40bb6

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

src/constants.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ export const ACTION_TYPES = {
66
SENDER_CONNECTED:5,
77
SENDER_DISCONNECTED:6,
88
ON_CONNECTION_ERROR:7,
9-
SET_FIELD:8
9+
RECEIVED_FIELD:8,
10+
SEND_FIELD:9
11+
12+
1013
};
1114

1215
export const MobileState = {

src/globalinput.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import QRCode from "qrcode.react";
44
import {ACTION_TYPES, MobileState} from './constants';
55
import { createMessageConnector } from 'global-input-message';
66

7-
export const initialData={
8-
connector:null,
9-
data:{
7+
const createInitialData=()=>({
108
fields:[],
119
values:[],
1210
setters:[],
13-
initData:null,
14-
},
11+
initData:null
12+
});
13+
export const initialData={
14+
connector:null,
15+
data:createInitialData(),
1516
onFieldChanged:()=>{},
1617

1718
};
@@ -27,8 +28,8 @@ export const setOnFieldChanged=(mobile,onFieldChanged)=>{
2728
export const closeConnection=(mobile)=>{
2829
if(mobile.current.connector){
2930
mobile.current.connector.disconnect();
30-
mobile.current.connector=null;
31-
mobile.current.data=null;
31+
mobile.current.connector=null;
32+
mobile.current.data=createInitialData();
3233
}
3334
};
3435

@@ -147,7 +148,8 @@ const processInitData=(mobile,dispatch, initData)=>{
147148
values.push(f.value);
148149
const s= (value)=>{
149150
values[index]=value;
150-
fields[index].value=value;
151+
fields[index].value=value;
152+
dispatch({type:ACTION_TYPES.SEND_FIELD});
151153
mobile.current.connector.sendInputMessage(value,index);
152154
};
153155
fieldSetters.push(s);
@@ -164,7 +166,7 @@ const processInitData=(mobile,dispatch, initData)=>{
164166
values[index]=value;
165167
fields[index].value=value;
166168
const nf={...fields[index],value};
167-
dispatch({type:ACTION_TYPES.SET_FIELD,field:nf});
169+
dispatch({type:ACTION_TYPES.RECEIVED_FIELD,field:nf});
168170
}
169171
}
170172
}

src/reducer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ export default (state, action)=>{
4747
errorMessage:action.errorMessage,
4848
mobileState:MobileState.ERROR
4949
};
50-
case ACTION_TYPES.SET_FIELD:
50+
case ACTION_TYPES.RECEIVED_FIELD:
5151
return {...state,field:action.field};
52+
case ACTION_TYPES.SEND_FIELD:
53+
return {...state};
5254
default:
5355
return state;
5456
};

0 commit comments

Comments
 (0)