pbomb / flow-immutable-models

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

Generated fromJS can omit state variable declaration #8

Closed object88 closed 7 years ago

object88 commented 7 years ago

Given model...

export type BazModelType = {
  bazNum: number,
  innerBazs: Array<InnerBazModelType>,
};

export type InnerBazModelType = {
  key: string,
  value: string,
}

... the codegen produces a fromJS for Baz which doesn't declare and initialize state:

static fromJS(json: BazModelType): Baz {
  state.innerBazs = state.innerBazs.map(item => InnerBaz.fromJS(item));
  return new Baz(Immutable.fromJS(json));
}

Proposal: instead of only creating a state variable if there is a default[ModelType]Values, always do so. Thoughts?