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,7 +96,7 @@ describe('navigation options', () => {
96 96
 
97 97
     // As we can't import external images and we don't want to add an image here
98 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 100
     expect(options.icon).toEqual(null);
101 101
     expect(options.topBar.myIcon).toEqual(null);
102 102
     expect(options.image).toEqual(null);
@@ -173,4 +173,38 @@ describe('navigation options', () => {
173 173
 
174 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,6 +37,7 @@ export class OptionsProcessor {
37 37
       _.forEach(value, (button) => {
38 38
         if (button.passProps && button.id) {
39 39
           this.store.setPropsForId(button.id, button.passProps);
40
+          button.passProps = undefined;
40 41
         }
41 42
       });
42 43
     }