constelation / monorepo

Mono repo for constelation's Components, functions, and CONSTANTS
https://constelation.github.io/monorepo/
MIT License
12 stars 3 forks source link

Idea: immutable View props #75

Open kylpo opened 7 years ago

kylpo commented 7 years ago

Could be opt-in, like $lazy={true}, where the component would not re-render on change of that field.

Or better yet, it could be immutable by default, with mutable opt-in, like $lazy={props.lazy}, where the component would re-render on change of that field.

Can I use flowtype to enforce this?

Pros: definitely perf gains, could set scu => false for any Views that don't have children, if they're all immutable props. Would make a babel transform easier, I think. Cons: DX. One more thing to learn, one more thing to update and be the source of errors.

all-caps option:

<Style_
  opacity={this.state.opacity}
  TRANSITION='opacity 400ms'
>
  <View
    HEIGHT={40}
    WIDTH={40}
  />
</Style_>

^ View would know to scu => false. Looks kind of ugly though.

kylpo commented 7 years ago

Actually, I like taking this to the component level, which enables much simpler logic.

<Style_
  opacity={this.state.opacity}
  transition='opacity 400ms'
>
  <VIEW
    height={40}
    width={40}
  />
</Style_>

or maybe go the way of Animated and use something like:

<Style_
  opacity={this.state.opacity}
  transition='opacity 400ms'
>
  <View.Pure
    height={40}
    width={40}
  />
</Style_>

I like the looks of all caps better, and like that it aligns with our all-caps constant convention. It does, however, require an additional import. View.Pure is uglier, but doesn't need the additional import.

"#importjs - buy my product" :P

mikehobi commented 7 years ago

The capitalization gives me nightmares of my early html days.

<HTML>
  <BODY>
    <FONT COLOR=BLUE>hello</FONT>
  </BODY>
</HTML>