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

Deprecate pushState and replaceState for new push and replace #168

Merged
merged 2 commits into from
Dec 6, 2015

Conversation

taion
Copy link
Contributor

@taion taion commented Dec 1, 2015

No description provided.

@taion taion force-pushed the doc-141 branch 2 times, most recently from ae4903d to 9ac2626 Compare December 1, 2015 15:30
@@ -115,6 +115,23 @@ A *location key* is a string that is unique to a particular [`location`](#locati

type LocationListener = (location: Location) => void;

### LocationSpec
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm like ~65% on this.

We lose a bit of conciseness by introducing this concept of a "location spec" object, but I think it's worthwhile to not entirely merge this concept into that of a "location", because of the omission of the action and key fields.

I'd be totally fine with merging this into the concept of a location if people feel that would make more sense, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I think this is the way to go.

@taion
Copy link
Contributor Author

taion commented Dec 1, 2015

This builds on top of the updated CHANGES format per #167, because I wanted to call out new features separately from bug fixes.

@taion taion changed the title Document the new push and replace syntax Deprecate pushState and replaceState for new push and replace Dec 3, 2015
@taion
Copy link
Contributor Author

taion commented Dec 3, 2015

Added a WIP with the deprecations. Still need to change the tests - thinking of putting together a codemod for that.

@@ -1,5 +1,11 @@
## [HEAD]

#### New features
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to further sub-divide this doc? I was hoping to keep each release small enough that we wouldn't have to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about labelling it as something like:

I just want an easy way for people looking at this to tell at a glance what has changed in which way - especially new features and deprecations, which might require some action on their part.

@mjackson
Copy link
Member

mjackson commented Dec 4, 2015

Looking good, @taion 👍 Just let me know when you're ready to merge.

@taion
Copy link
Contributor Author

taion commented Dec 4, 2015

Probably not today unless it's later :

I was hoping to use JSCodeShift to update the tests, but I have to learn how to use JSCodeShift first.

@taion
Copy link
Contributor Author

taion commented Dec 4, 2015

I mean, not because there are so many tests that I can't update them by hand, more that I think JSCodeShift is super cool, and that it'd be nice to offer a codemod to our users.

@taion taion mentioned this pull request Dec 5, 2015
4 tasks
@taion
Copy link
Contributor Author

taion commented Dec 5, 2015

@timdorr

Continuing from remix-run/react-router#2646 (comment), the "location descriptor" or "location spec" or whatever is slightly different enough that we'd avoid some confusion by calling it something else. There's no action or key attached to it, so it's not exactly the same.

One example of the difference is that when using queries, your "location descriptor" might look like:

{
  pathname: '/foo',
  query: { the: 'query' },
}

But the corresponding "location" is more like:

{
  pathname: '/foo',
  query: { the: 'query' },
  search: '?the=query',
  action: 'POP',
  key: 'asdf12',
}

It's really a shorthand object that is enough to describe or specify a location, but is not a location itself.

@taion
Copy link
Contributor Author

taion commented Dec 6, 2015

Got the codemod running: https://gist.github.com/taion/0b752445e86304f5f5c2

Doing final cleanups now, will update PR shortly.

What do we want to do with the transform? Ideally we'd ship it to users somehow.

@taion
Copy link
Contributor Author

taion commented Dec 6, 2015

PR updated. This is ready to go from my end, assuming we don't want to ship the transform with this package.

I'm really impressed with JSCodeShift. All the test updates on the 2nd commit were with JSCodeShift, except:

  • I manually backed out the change in BrowserHistory-test.js (I was too lazy to specifically omit window.history.pushState calls from the transform)
  • I moved the PUSH -> REPLACE logic from describePushState.js to describePush.js
  • The transform gave me double quotes instead of single quotes on string literals and I had to run npm run lint -- --fix to clean those up

@mjackson
Copy link
Member

mjackson commented Dec 6, 2015

Thanks @taion. I'll take a look.
On Sat, Dec 5, 2015 at 4:19 PM Jimmy Jia notifications@github.com wrote:

PR updated. This is ready to go from my end, assuming we don't want to
ship the transform with this package.

I'm really impressed with JSCodeShift. All the test updates on the 2nd
commit were with JSCodeShift, except:

  • I manually backed out the change in BrowserHistory-test.js (I was
    too lazy to specifically omit window.history.pushState calls from the
    transform)
  • I moved the PUSH -> REPLACE logic from describePushState.js to
    describePush.js
  • The transform gave me double quotes instead of single quotes on
    string literals and I had to run npm run lint -- --fix to clean those
    up


Reply to this email directly or view it on GitHub
#168 (comment).

@timdorr
Copy link
Member

timdorr commented Dec 6, 2015

You could drop it in the scripts folder. That's probably the best place for it. It's an optional thing anyways.

@taion
Copy link
Contributor Author

taion commented Dec 6, 2015

Sorry, had to manually update a few more tests. There were a few meant to intentionally cover pushState and replaceState that I restored to their old forms, and I had to update a few test descriptions as well.

@taion
Copy link
Contributor Author

taion commented Dec 6, 2015

@timdorr It's not a script per se, though - you can only run it through jscodeshift, so it's not especially helpful on its own.

@timdorr
Copy link
Member

timdorr commented Dec 6, 2015

Yeah, but you would run it once for automating the upgrade to this API version. That sounds script-y to me 😄

@taion
Copy link
Contributor Author

taion commented Dec 6, 2015

Oh, I missed the "single quote" recast option. Well, ESLint fixed it for me anyway.

@timdorr I was thinking of using transforms/ instead, though - it's what the upstream codemod packages do: https://github.com/reactjs/react-codemod, https://github.com/cpojer/js-codemod/. They're set up as separate packages there, though.

@taion
Copy link
Contributor Author

taion commented Dec 6, 2015

Assuming we go forward with this PR as-is or in slightly modified form, I'm going to set up a rackt-codemod repo under this org, and distribute the codemod there.

@timdorr
Copy link
Member

timdorr commented Dec 6, 2015

I was just going to suggest this. If you don't mind, could you create separate folders for each repo that has codemods (just history for now)?

@taion
Copy link
Contributor Author

taion commented Dec 6, 2015

👍 Will do.

@mjackson
Copy link
Member

mjackson commented Dec 6, 2015

@taion Looks like you're ready to merge here?

@@ -105,6 +104,23 @@ A *location* answers two important (philosophical) questions:

New locations are typically created each time the URL changes. You can read more about locations in [the `history` docs](https://github.com/rackt/history/blob/master/docs/Location.md).

### LocationDescriptor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for this name. I was actually thinking about using this name too :)

@taion
Copy link
Contributor Author

taion commented Dec 6, 2015

Yes, this is good to go from my end. Anything else I need to fix before we merge?

@timdorr
Copy link
Member

timdorr commented Dec 6, 2015

@taion Needs a rebase on master now.

@taion
Copy link
Contributor Author

taion commented Dec 6, 2015

Yup, done! Thanks.

@mjackson
Copy link
Member

mjackson commented Dec 6, 2015

Thanks, @taion. This turned out to be quite a bit of work!

mjackson added a commit that referenced this pull request Dec 6, 2015
Deprecate pushState and replaceState for new push and replace
@mjackson mjackson merged commit 990b853 into remix-run:master Dec 6, 2015
@taion taion deleted the doc-141 branch December 6, 2015 17:14
@taion
Copy link
Contributor Author

taion commented Dec 6, 2015

It was fun, though, and the long-term API cleanup is going to be really sweet. Just need to fix createPath and createHref and deprecate createLocation.

@taion
Copy link
Contributor Author

taion commented Dec 6, 2015

Oh crud, the warnings for state without queryKey aren't there on push and replace for createHashHistory. Bah.

gaboesquivel added a commit to gaboesquivel/redux-simple-router that referenced this pull request Dec 7, 2015
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants