Skip to content

Initialisation of Record Map #40

@irisSchaffer

Description

@irisSchaffer

Hey there!

Great library, I just have one little problem/question about this line of code: see https://github.com/glenjamin/transit-immutable-js/blob/master/index.js#L215
Is there a reason for initialising the Records there? Or rather: is there a reason for initialising them with an empty Object ({})?

In my case, I have Records with a constructor and because of the initialisation of the Record with {}, I can't use default parameters ({ meta : {} }) and need to check if my nested object structures exist everywhere (data.meta && data.meta.title || ...):

export default class StartPage extends StartPageRecord {
  constructor(data = { meta : {} }, name) { // this here won't work
    super({
      ...data,
      selected : new Set(data.selected),
      image    : new Image(data.image),
      meta     : new Meta({
        title       : data.meta.title || data.title, // these throw errors
        description : data.meta.description || data.subtitle // because data.meta is undefined
      }),
      socialLinks : new SocialLinks(data.socialLinks)
    }, name)
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions