Skip to content
This repository was archived by the owner on Sep 9, 2019. It is now read-only.

BabelPlugin for masking _ prop api. #2

Open
blainekasten opened this issue Apr 20, 2016 · 0 comments
Open

BabelPlugin for masking _ prop api. #2

blainekasten opened this issue Apr 20, 2016 · 0 comments

Comments

@blainekasten
Copy link
Owner

The idea here is that https://github.com/blainekasten/coflux/tree/master/docs#mapped-props-with-_ is an awkward API that could be auto-generated by a babel transform.

The _ is a perf gain because components sometimes can modify data they aren't rendering. For example a component with a delete all button isn't likely rendering anything based on state, but clicking it will empty an array.

e.g.,

function DeleteAll({actions}) {
  return <button onClick={actions.deleteAll}>Delete All</button>;
}

wrap(DeleteAll, {
  mapStateToProps() {
    return {
      emailList: 'app.user.emails';
    };
  },

  actions: {
    deleteAll({emailList}, next) {
      next({emailList: null});
      /*
       * We need to know about emailList so we can modify it
       * But we dont' need to re-render if the list changes,
       * because we aren't rendering it.
       */
    }
  }
});

So we have this perf optimization (that could change, but for now it works) that a mapped prop prefixed with _ is marked as write-only. Meaning it doesn't read from it, and doesn't care if the value changes.

While this makes sense, it'd be best if we could have a babel transform, that could read the components render function, and determine what props are write-only and autoprefix the keys with _.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant