Browse Source

Omit passProps from components passed in options

Options are handled in Js and should not be passed over the bridge as that may
cause serialisation errors. Omitting passProps reduces the amount of data passed over the
bridge as well.
Guy Carmeli 6 years ago
parent
commit
b94bdca371
2 changed files with 36 additions and 1 deletions
  1. 35
    1
      lib/src/commands/OptionsProcessor.test.ts
  2. 1
    0
      lib/src/commands/OptionsProcessor.ts

+ 35
- 1
lib/src/commands/OptionsProcessor.test.ts View File

96
 
96
 
97
     // As we can't import external images and we don't want to add an image here
97
     // As we can't import external images and we don't want to add an image here
98
     // I assign the icons to strings (what the require would generally look like)
98
     // I assign the icons to strings (what the require would generally look like)
99
-    // and expect the value to be resovled, in this case it doesn't find anything and returns null
99
+    // and expect the value to be resolved, in this case it doesn't find anything and returns null
100
     expect(options.icon).toEqual(null);
100
     expect(options.icon).toEqual(null);
101
     expect(options.topBar.myIcon).toEqual(null);
101
     expect(options.topBar.myIcon).toEqual(null);
102
     expect(options.image).toEqual(null);
102
     expect(options.image).toEqual(null);
173
 
173
 
174
     expect(options.someImage).toEqual(undefined);
174
     expect(options.someImage).toEqual(undefined);
175
   });
175
   });
176
+
177
+  it('omits passProps when processing options', () => {
178
+    const passProps = {
179
+      topBar: {
180
+        rightButtons: [
181
+          {
182
+            passProps: {},
183
+            id: 'btn1'
184
+          },
185
+        ],
186
+        leftButtons: [
187
+          {
188
+            passProps: {},
189
+            id: 'btn2'
190
+          }
191
+        ],
192
+        title: {
193
+          component: {
194
+            passProps: {}
195
+          }
196
+        },
197
+        background: {
198
+          component: {
199
+            passProps: {}
200
+          }
201
+        }
202
+      }
203
+    };
204
+    uut.processOptions(passProps);
205
+    expect(passProps.topBar.rightButtons[0].passProps).toBeUndefined();
206
+    expect(passProps.topBar.leftButtons[0].passProps).toBeUndefined();
207
+    expect(passProps.topBar.title.component.passProps).toBeUndefined();
208
+    expect(passProps.topBar.background.component.passProps).toBeUndefined();
209
+  });
176
 });
210
 });

+ 1
- 0
lib/src/commands/OptionsProcessor.ts View File

37
       _.forEach(value, (button) => {
37
       _.forEach(value, (button) => {
38
         if (button.passProps && button.id) {
38
         if (button.passProps && button.id) {
39
           this.store.setPropsForId(button.id, button.passProps);
39
           this.store.setPropsForId(button.id, button.passProps);
40
+          button.passProps = undefined;
40
         }
41
         }
41
       });
42
       });
42
     }
43
     }