rescript-react-native icon indicating copy to clipboard operation
rescript-react-native copied to clipboard

ReScript 10 / records with optional fields

Open cknitt opened this issue 3 years ago • 11 comments

ReScript 10 will support records with optional fields. This would allow us to simplify a lot of things/move them closer to how they are done in JS.

E.g., styles: Instead of

let styles = StyleSheet.create({
  open Style
  {
    "statusBar": style(
      ~flexDirection=#row,
      ~height=dp(22.),
      ~alignItems=#center,
      ~paddingLeft=dp(12.),
      (),
    ),
    "text": style(~color=NativeColors.white, ~marginLeft=dp(4.), ()),
  }
})

we could have

let styles = StyleSheet.create({
  open Style
  {
    "statusBar": style({
      flexDirection: #row,
      height: dp(22.),
      alignItems: #center,
      paddingLeft: dp(12.),
    }),
    "text": style({
      color: "white",
      marginLeft: dp(4.),
    }),
  }
})

Or for APIs taking some config object, like

Share.share(Share.content(~title="Title", ~url="https://example.com", ()))

we could have

Share.share({title: "Title", url: "https://example.com"})

@MoOx For me the question is, can these be breaking changes or should we try to remain compatible with the existing way where possible?

If we go for breaking changes, then we could also do #748 at the same time.

cknitt avatar Aug 04 '22 03:08 cknitt

I guess we can do breaking changes. This will be painful to migrate but it will be more easy for new comers. Alternatively, since we have bindings, we could offers 2 version, deprecate one, and later kill old ones ? Maybe a open ReactNative_Alt or something that could help people to slowly migrate ?

MoOx avatar Aug 10 '22 11:08 MoOx

@MoOx We can do it like this:

type content = {
  title?: string,
  message?: string,
  url?: string,
}

@obj @deprecated("Directly create record instead")
external content: (~title: string=?, ~message: string=?, ~url: string=?, unit) => content = ""

The record with optional fields will not even compile with pre-10.x compiler versions though.

cknitt avatar Aug 11 '22 08:08 cknitt

That's why I didn't merged #767. I wanted to do a release before a v10 only version.

MoOx avatar Aug 11 '22 10:08 MoOx

Oh, sorry, I thought #767 was ready to merge as you had approved it.

If you want all breaking changes in the v10 release, then we can either revert #767 or continue with the v10 stuff on master and create a 9.x "maintenance branch". What would you prefer?

cknitt avatar Aug 11 '22 12:08 cknitt

Yes I prefer major changes associated with v10 release indeed. I will revert #767 and reopen the PR and keep opened PRs with a milestone for React Native 0.70 (coming very soon, it's in RC 3 or something like that). Meanwhile, I will cut a 0.69 release with a solution for hitSlop #765

MoOx avatar Aug 18 '22 07:08 MoOx

Just to let you know, I am on vacations with limited access to computer & web, I will handle all this release when I get back, mid September.

MoOx avatar Sep 02 '22 06:09 MoOx

@MoOx How shall we proceed regarding a "ReScript 10" release with the breaking changes? I think more breaking changes are to come with JSX 4 in 10.1, so it makes sense to wait for 10.1.

However, shall we merge the corresponding PRs to some "future" branch or something? So that we have something to test with already?

cknitt avatar Oct 03 '22 06:10 cknitt

I guess waiting to release for JSX 4 is a good thing for official release. I was undecided for the hitSlop thing & didn't do anything...

I will handle 0.69 release & will merge everything in main branch for 0.70 release :)

MoOx avatar Oct 04 '22 11:10 MoOx

Busy day, I have released 0.69 today and will review & merge all pending PR tomorrow morning :)

MoOx avatar Oct 04 '22 13:10 MoOx

@cknitt when will be released JSX 4 approximately ?

MoOx avatar Oct 04 '22 13:10 MoOx

It will be part of ReScript 10.1. A few more weeks and a few more alpha/beta releases of ReScript 10.1 I guess.

Maybe @mattdamon108 and @cristianoc can comment on that?

cknitt avatar Oct 04 '22 14:10 cknitt