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
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


## 3.3.5
* [#269](https://github.com/DockYard/ember-router-scroll/pull/269) [Enhancement]: improve idle case with improved scrollTo under high loads

Expand Down
97 changes: 48 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ preserved when using the back or forward browser buttons.
Compatibility
------------------------------------------------------------------------------

* Ember.js v2.18 or above
* Ember CLI v2.13 or above
* Ember.js v3.12 or above
* Ember CLI v3.12 or above


Installation
Expand All @@ -31,7 +31,12 @@ ember install ember-router-scroll
```


Usage
Usage > 4.x
------------------------------------------------------------------------------

Nothing to initialize.

Usage < 4.x
------------------------------------------------------------------------------

**1.** Import ember-router-scroll
Expand Down Expand Up @@ -60,6 +65,9 @@ const Router = EmberRouter.extend(RouterScroll, {
});
```

Remaining optional steps for all versions 2.x - 4.x
------------------------------------------------------------------------------

**2.** Enable `historySupportMiddleware` in your app

Edit `config/environment.js` and add `historySupportMiddleware: true,` to get live-reload working in nested routes.
Expand All @@ -70,15 +78,6 @@ historySupportMiddleware: true,
```

This location type inherits from Ember's `HistoryLocation`.

**3.** If using old style QUnit tests. If tests based on [RFC](https://github.com/emberjs/rfcs/pull/232), you can
ignore this.
In your router and controller tests, add `'service:router-scroll'` and `'service:scheduler'` as dependencies in the
`needs: []` block:

```javascript
//{your-app}}/tests/unit/routes/{{your-route}}.js
needs:[ 'service:router-scroll', 'service:scheduler' ],
```


Expand Down Expand Up @@ -108,7 +107,7 @@ ENV['routerScroll'] = {

#### Scroll Timing

You may want the default "out of the box" behaviour. We schedule scroll after Ember's `render`. This occurs on the tightest schedule between route transition start and end.
You may want the default "out of the box" behaviour. We schedule scroll immediately after Ember's `render`. This occurs on the tightest schedule between route transition start and end.

However, you have other options. If you need an extra tick after `render`, set `scrollWhenAfterRender: true`. You also may need to delay scroll functionality until the route is idle (approximately after the first paint completes) using `scrollWhenIdle: true` in your config. `scrollWhenIdle` && `scrollWhenAfterRender` defaults to `false`.

Expand Down Expand Up @@ -182,19 +181,19 @@ Example:
```javascript
import Controller from '@ember/controller';

export default Controller.extend({
queryParams: [
export default class MyController extends Controller {
queryParams = [
'preserveScrollPosition',
],
});
];
}
```

**2.** Pass in query param

Next, in the place where a transition is triggered, pass in `preserveScrollPosition=true`. For example

```handlebars
{{link-to "About Tab" 'tab.about' (query-params preserveScrollPosition=true) }}
<LinkTo "About Tab" "tab.about" {{query-params preserveScrollPosition=true}} />
```


Expand All @@ -217,19 +216,19 @@ Example:

```javascript
import Controller from '@ember/controller';
import { action } from '@ember/object';

export default Controller.extend({
queryParams: ['filter'],
export default class MyController extends Controller {
queryParams = ['filter'];

preserveScrollPosition: false,
preserveScrollPosition = false;

actions: {
changeFilter(filter) {
this.set('preserveScrollPosition', true);
this.set('filter', filter);
}
@action
changeFilter(filter) {
this.set('preserveScrollPosition', true);
this.set('filter', filter);
}
});
}
```

**2.** Reset preserveScrollPosition if necessary
Expand All @@ -241,11 +240,11 @@ where `preserveScrollPosition` is always set to true.
```javascript
import Router from '@ember/routing/route';

export default Route.extend({
export default class MyRoute extends Route {
resetController(controller) {
controller.set('preserveScrollPosition', false);
}
});
}
```


Expand All @@ -269,28 +268,28 @@ When you need to modify `preserveScrollPosition` on the service for a specific t
Example:

```javascript
import Component from '@ember/component';
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';

export default Component.extend({
routerScroll: service(),
router: service(),

actions: {
async goToPaginationPage(pageNumber) {
this.set('routerScroll.preserveScrollPosition', true);
await this.router.transitionTo(
this.router.currentRouteName,
{
queryParams: { page: pageNumber }
}
);

// Reset `preserveScrollPosition` after transition so future transitions behave as expected
this.set('routerScroll.preserveScrollPosition', false);
}
import { action } from '@ember/object';

export default class MyComponent extends Component {
@service routerScroll;
@service router;

@action
async goToPaginationPage(pageNumber) {
this.set('routerScroll.preserveScrollPosition', true);
await this.router.transitionTo(
this.router.currentRouteName,
{
queryParams: { page: pageNumber }
}
);

// Reset `preserveScrollPosition` after transition so future transitions behave as expected
this.set('routerScroll.preserveScrollPosition', false);
}
});
}
```

## Running Tests
Expand Down
172 changes: 0 additions & 172 deletions addon/index.js

This file was deleted.

8 changes: 8 additions & 0 deletions addon/instance-initializers/ember-router-scroll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function initialize(appInstance) {
// Eagerly initialize service
appInstance.lookup('service:router-scroll');
}

export default {
initialize
};
Loading