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

Added params.backbutton #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

ile
Copy link

@ile ile commented Jul 25, 2014

I needed a way to detect if the page was rendered by the user pressing the back button. In case it was, I didn't do anything, but in case it was rendered "normally" (clicking a link), I called window.scrollTo(0,0); to scroll the page to the top. This is the way it usually works I believe (on the web without Derby) - the page is scrolled to the top.

So, this feature adds params.backbutton = true to the route callbacks (page, model, params, next).

@ile
Copy link
Author

ile commented Jul 25, 2014

Not sure if scrolling should be part of Derby (built-in)?

@@ -137,5 +137,6 @@ RenderReq.prototype.routeParams = function(route) {
params.body = this.body
params.query = this.query
params.method = this.method
params.backbutton = this.options.backbutton
Copy link
Contributor

Choose a reason for hiding this comment

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

i think this should have a null check (if this.options)

Copy link
Author

Choose a reason for hiding this comment

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

Yes, perhaps, but it seemed like options would always have a value (an object):

called here
https://github.com/ilkkah/tracks/blob/feature-backbutton/lib/router.js#L30
and here:
https://github.com/ilkkah/tracks/blob/feature-backbutton/lib/History.js#L46
https://github.com/ilkkah/tracks/blob/feature-backbutton/lib/History.js#L76
https://github.com/ilkkah/tracks/blob/feature-backbutton/lib/History.js#L217
https://github.com/ilkkah/tracks/blob/feature-backbutton/lib/History.js#L228

But I'm not sure if it's is called from other modules. I quickly checked but couldn't find anything.

Should I add the check? It's ok to me. Not sure what your practice is here (how strict).

Copy link
Contributor

Choose a reason for hiding this comment

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

We prefer to have null checks because it can crash a process if you forget
it. Options are usually optional, so making sure there is a reasonable
response when the options are missing is preferred.

On Thu, Aug 7, 2014 at 11:41 PM, Ilkka Huotari [email protected]
wrote:

In lib/router.js:

@@ -137,5 +137,6 @@ RenderReq.prototype.routeParams = function(route) {
params.body = this.body
params.query = this.query
params.method = this.method

  • params.backbutton = this.options.backbutton

Yes, perhaps, but it seemed like options would always have a value (an
object).

called here
https://github.com/ilkkah/tracks/blob/feature-backbutton/lib/router.js#L30
and here:
https://github.com/ilkkah/tracks/blob/feature-backbutton/lib/History.js#L46
https://github.com/ilkkah/tracks/blob/feature-backbutton/lib/History.js#L76

https://github.com/ilkkah/tracks/blob/feature-backbutton/lib/History.js#L217

https://github.com/ilkkah/tracks/blob/feature-backbutton/lib/History.js#L228

But I'm not sure if it's is called from other modules. I quickly checked
but couldn't find anything.

Should I add the check? It's ok to me. Not sure what your practice is here
(how strict).


Reply to this email directly or view it on GitHub
https://github.com/derbyjs/tracks/pull/20/files#r15979820.

Ian Johnson - 周彦
http://enja.org

@ile
Copy link
Author

ile commented Oct 24, 2014

How about this? ^---check if options exists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants