Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve interleaved whitespace between record expression rows #2152

Merged
merged 1 commit into from
Aug 24, 2018

Conversation

IwanKaramazow
Copy link
Contributor

Allows whitespace interleaving between rows of record expressions.
It's hard to see the forest through the trees when scanning through Reason code containing record expression with rows packed on top of each other. By preserving one newline (if the user wrote n >= 1),
the code becomes much clearer to read and a pleasure to write. This also aligns user's expectations in terms of the output that Prettier produces.

Example:

let make = _children => {
  ...component,

  initialState: () => {
    posts: [],
    activeRoute: urlToRoute(ReasonReact.Router.dangerouslyGetInitialUrl()),
  },

  didMount: self => {
    let watcherID =
      ReasonReact.Router.watchUrl(url =>
        self.send(ChangeRoute(urlToRoute(url)))
      );
    self.onUnmount(() => ReasonReact.Router.unwatchUrl(watcherID));
  },

  reducer: (action, state) =>
    switch (action) {
    | ChangeRoute(activeRoute) => ReasonReact.Update({...state, activeRoute})
    | FetchCats => ReasonReact.NoUpdate
    },

  render: ({state: {posts, activeRoute}}) =>
    <div>
      <h1> <a href="/"> {ReasonReact.string("Instagram")} </a> </h1>
      {
        switch (activeRoute) {
        | Default => <Grid posts />
        | Detail(postId) => <Single posts postId />
        }
      }
    </div>,
};

@chenglou
Copy link
Member

cc @anmonteiro good to know

@chenglou chenglou merged commit 1bea873 into reasonml:master Aug 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants