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

[Major]: refactor: useRouterService instead of Ember Router #270

Merged
merged 21 commits into from
Jan 6, 2021
Merged

Conversation

snewcomer
Copy link
Collaborator

@snewcomer snewcomer commented Dec 24, 2020

close #256 close #255

This will be released as a major bump -> 4.0

  • remove locations/router-scroll.js. This has been deprecated and you should rely on Ember's own implementation instead of extending from us. HistoryLocation Subclass Question #193
  • Remove EmberRouterScroll that you used to import and extend in your application. We handle that for you now and eagerly initialize the service for you. We did this because we can rely on RouterService events instead of this.

buschtoens and others added 3 commits July 29, 2020 17:47
This fixes the following error:

```
Build Error (broccoli-persistent-filter:Babel > [Babel: @ember/test-helpers]) in @ember/test-helpers/dom/-is-focusable.js

Cannot find module '@babel/compat-data/corejs3-shipped-proposals'
Require stack:
- /Users/jan/open-source/ember-router-scroll/node_modules/@babel/preset-env/lib/polyfills/corejs3/usage-plugin.js
- /Users/jan/open-source/ember-router-scroll/node_modules/@babel/preset-env/lib/index.js
- /Users/jan/open-source/ember-router-scroll/node_modules/@babel/core/lib/config/files/plugins.js
- /Users/jan/open-source/ember-router-scroll/node_modules/@babel/core/lib/config/files/index.js
- /Users/jan/open-source/ember-router-scroll/node_modules/@babel/core/lib/index.js
- /Users/jan/open-source/ember-router-scroll/node_modules/broccoli-babel-transpiler/lib/worker.js
```
@snewcomer snewcomer self-assigned this Dec 24, 2020
@snewcomer snewcomer changed the title Pr/256 refactor: useRouterService instead of Ember Router Dec 25, 2020
@snewcomer
Copy link
Collaborator Author

@buschtoens 👋 Let me know what you think!!

@snewcomer
Copy link
Collaborator Author

@simonihmig as well if you have a moment!

@snewcomer snewcomer changed the title refactor: useRouterService instead of Ember Router [Major]: refactor: useRouterService instead of Ember Router Jan 5, 2021
Copy link
Contributor

@jleja jleja left a comment

Choose a reason for hiding this comment

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

Looks good. Just had two things to point out.

preserveScrollPosition = get(this, 'preserveScrollPosition')
}

if (!preserveScrollPosition) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can combine the two if (!preserveScrollPosition) blocks

Comment on lines 178 to 182
// out of the option, this happens on the tightest schedule
scheduleOnce('render', this, CALLBACK, transition);
} else if (scrollWhenAfterRender && !scrollWhenIdle) {
// out of the option, this happens on the tightest schedule
scheduleOnce('afterRender', this, CALLBACK, transition);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the duplicated comments here correct, or is scheduling after render the option that happens on the tightest schedule?

Copy link
Contributor

@cbroeren cbroeren left a comment

Choose a reason for hiding this comment

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

I wasn't able to verify this addon with a running app yet, but left some comments. Looks 👍 overall

@@ -2,6 +2,9 @@

- Updating to th v3.0 series was due to removing `scrollWhenPainted` as a config option. Also, we fixed some hidden bugs with scheduling when to scroll to your last y position.

## 4.0.0
* [#270](https://github.com/DockYard/ember-router-scroll/pull/270) [Major]: use`RouterService` instead of Ember `Router`
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be helpful to also mention the changes users should make on updating to this version? Or do you expect them to find that in the PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great idea! I updated the README.


// If `preserveScrollPosition` was not set on the controller, attempt fallback to `preserveScrollPosition` which was set on the router service.
if (!preserveScrollPosition) {
preserveScrollPosition = get(this, 'preserveScrollPosition')
Copy link
Contributor

Choose a reason for hiding this comment

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

Mind adding this logic to the initial assignment? Double assignment and the two same if blocks are a bit confusing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is a good idea!

if (url && url.indexOf('#') > -1 && hashElement) {
scrollPosition = { x: hashElement.offsetLeft, y: hashElement.offsetTop };
} else {
scrollPosition = get(this, 'position');
Copy link
Contributor

Choose a reason for hiding this comment

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

What if you use this as the initial value (it gets overwritten in the if block if needed)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Another good find. Thank you Chantal!

addon/services/router-scroll.js Outdated Show resolved Hide resolved

if (!preserveScrollPosition) {
const scrollElement = get(this, 'scrollElement');
const targetElement = get(this, 'targetElement');
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need the get or could you use const { scrollElement, targetElement } = this; ?

// out of the option, this happens on the tightest schedule
scheduleOnce('render', this, CALLBACK, transition);
} else if (scrollWhenAfterRender && !scrollWhenIdle) {
// out of the option, this happens on the tightest schedule
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be the same comment as above?

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.

Use RouterService instead of extending Ember Router
4 participants