@miot-rn/common-component 1.0.2 → 1.0.3

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.
@@ -6,6 +6,26 @@ import { encodeProp, decodeProp, specsToSubscribeKeys, specAccess } from "../../
6
6
  import { OK } from "./error-code";
7
7
  const specSubject = new Subject(getEventGenerator('std_spec_subject', encodeProp));
8
8
  let receivedMessagesSubscription = null;
9
+ function fillInfo(props) {
10
+ const propsNew = props.filter(element => {
11
+ return element !== null;
12
+ });
13
+ return propsNew.map(prop => {
14
+ const {
15
+ did,
16
+ miid,
17
+ ...rest
18
+ } = prop;
19
+ const t = {
20
+ ...rest,
21
+ did: did || Device.deviceID
22
+ };
23
+ if (miid) {
24
+ t.miid = miid;
25
+ }
26
+ return t;
27
+ });
28
+ }
9
29
  export function getProps(props, chunkFn) {
10
30
  // console.log('getProps---props', props);
11
31
  // 处理固件不上报的情况,此时须将dataSource 设置为2,强行从固件读取
@@ -16,7 +36,7 @@ export function getProps(props, chunkFn) {
16
36
  siid,
17
37
  piid,
18
38
  did = Device.deviceID,
19
- dataSource = prop.fromSource ? 1 : 2
39
+ dataSource = 1
20
40
  } = prop;
21
41
  const p = {
22
42
  siid,
@@ -183,26 +203,6 @@ function subscribeReceivedMessage() {
183
203
  });
184
204
  });
185
205
  }
186
- function fillInfo(props) {
187
- const propsNew = props.filter(element => {
188
- return element !== null;
189
- });
190
- return propsNew.map(prop => {
191
- const {
192
- did,
193
- miid,
194
- ...rest
195
- } = prop;
196
- const t = {
197
- ...rest,
198
- did: did || Device.deviceID
199
- };
200
- if (miid) {
201
- t.miid = miid;
202
- }
203
- return t;
204
- });
205
- }
206
206
  export function subscribe(props, listener) {
207
207
  if (!receivedMessagesSubscription) {
208
208
  receivedMessagesSubscription = subscribeReceivedMessage();
@@ -8,7 +8,7 @@ declare const useGlobalSpecManager: import("zustand").UseBoundStore<import("zust
8
8
  subscribedSpecs: Set<unknown>;
9
9
  specUpdateListeners: never[];
10
10
  addSpecUpdateListener: (listener: any) => () => void;
11
- fetchSpecs: (specs: any, fromSource?: boolean, batchUpdate?: boolean) => Promise<({
11
+ fetchSpecs: (specs: any, datasource?: number, batchUpdate?: boolean) => Promise<({
12
12
  code: number;
13
13
  message: string;
14
14
  spec: any;
@@ -167,7 +167,7 @@ export declare const useSpecMetaInfo: (spec: any) => any;
167
167
  export declare const useSpecUpdateListener: (listener: any) => void;
168
168
  export declare const useEventListener: (eventSpec: any, listener: any) => () => void;
169
169
  export declare const addSpecUpdateListener: (listener: any) => () => void;
170
- export declare const fetchSpecs: (specs: any, fromSource?: boolean, batchUpdate?: boolean) => Promise<({
170
+ export declare const fetchSpecs: (specs: any, datasource?: number, batchUpdate?: boolean) => Promise<({
171
171
  code: number;
172
172
  message: string;
173
173
  spec: any;
@@ -115,12 +115,12 @@ const useGlobalSpecManager = create((set, get) => ({
115
115
  * @function fetchSpecs
116
116
  * @memberof useGlobalSpecManager
117
117
  * @param {Array<object>} specs - Spec对象数组,每个对象必须包含 siid 属性
118
- * @param {boolean} [fromSource=true] - 是否强制从源获取数据
118
+ * @param {number} [datasource=1] - 数据源:1=优先服务器缓存 2=直接下发rpc(最新值) 3=直接读缓存
119
119
  * @param {boolean} [batchUpdate=false] - 是否批量更新状态
120
120
  * @returns {Promise<Array<object>>} 返回包含每个Spec读取结果的数组
121
121
  * @throws {Error} 当入参无效或读取过程中发生异常时抛出错误
122
122
  */
123
- fetchSpecs: async (specs, fromSource = true, batchUpdate = false) => {
123
+ fetchSpecs: async (specs, datasource = 1, batchUpdate = false) => {
124
124
  // 边界验证:specs 必须是数组且非空
125
125
  if (!Array.isArray(specs) || specs.length === 0) {
126
126
  console.log(`[STD-LOCK][${TAG}][fetchSpecs][${new Date().toISOString()}] 入参 specs 必须为非空数组`);
@@ -142,10 +142,8 @@ const useGlobalSpecManager = create((set, get) => ({
142
142
  const key = toKey(spec);
143
143
  const results = await getProps([{
144
144
  ...spec,
145
- fromSource
146
- }], {
147
- fromSourceIfNeed: fromSource
148
- });
145
+ dataSource: datasource
146
+ }]);
149
147
  // data manager返回的结果code是0,但value是null,需要两者都判断
150
148
  if (results[0]?.code === 0 && results[0]?.value != null) {
151
149
  const updateTime = Math.floor(Date.now() / 1000);
@@ -799,11 +797,11 @@ export const addSpecUpdateListener = listener => {
799
797
  /**
800
798
  * 读取设备 spec
801
799
  * @param specs Spec 对象数组
802
- * @param fromSource 是否强制从设备/服务端获取
800
+ * @param datasource 数据源:1=优先服务器缓存 2=直接下发rpc(最新值) 3=直接读缓存
803
801
  * @param batchUpdate 是否批量更新状态
804
802
  */
805
- export const fetchSpecs = async (specs, fromSource = true, batchUpdate = false) => {
806
- return useGlobalSpecManager.getState().fetchSpecs(specs, fromSource, batchUpdate);
803
+ export const fetchSpecs = async (specs, datasource = 1, batchUpdate = false) => {
804
+ return useGlobalSpecManager.getState().fetchSpecs(specs, datasource, batchUpdate);
807
805
  };
808
806
 
809
807
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miot-rn/common-component",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "scripts": {
5
5
  "build": "rm -rf dist && rm -f tsconfig.tsbuildinfo && tsc && babel src -d dist --config-file ../../babel.config.js --extensions '.ts,.tsx' --verbose",
6
6
  "lint": "eslint src/**/*.ts",
@@ -23,5 +23,5 @@
23
23
  "react-native": "0.61.0",
24
24
  "zustand": "^4.4.1"
25
25
  },
26
- "gitHead": "2920def2cc542a8d0efcf100814e477830d94bb3"
26
+ "gitHead": "fca543751a7f8e62f9b52737ed8c56134b5fc096"
27
27
  }