pbomb / flow-immutable-models

Generates model classes from Flow types using Immutable.js
42 stars 8 forks source link

Fix problem with Arrays of ModelTypes in fromJS #7

Closed object88 closed 7 years ago

object88 commented 7 years ago

Given...

export type FooModelType = {
  barAry: Array<BarModelType>,
};

Original code was generating...

  static fromJS(json: $Diff<FooModelType, typeof defaultFooValues>): Foo {
    // [...]
    state.barAry = state.barAry.map(item => item.fromJS(item));
    // [...]
  }

When invoking Foo.fromJS and passing in { barAry: [{...}] }, code would throw error, item.fromJS is not a function.

New code correctly(?) generates...

  static fromJS(json: $Diff<FooModelType, typeof defaultFooValues>): Foo {
    // [...]
    state.barAry = state.barAry.map(item => Bar.fromJS(item));
    // [...]
  }
pbomb commented 7 years ago

LGTM. I'll add a test for the Array<*ModelType> case.