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

retrieving the current request "state" ? #7

Open
hems opened this issue Dec 24, 2015 · 3 comments
Open

retrieving the current request "state" ? #7

hems opened this issue Dec 24, 2015 · 3 comments

Comments

@hems
Copy link

hems commented Dec 24, 2015

How can i retrieve the state associated with a request?

For instance:

ways = require( "ways" )
ways( "/save", function( req ) {

  console.log( "How to retrieve the state object here?", req );

} );
ways.go( "/save", "", { hi: true } )
@arboleya
Copy link
Owner

Good one, I wonder how it never popped out before. 😄

Ideally it should be:

ways( "/route", function( req, params, state ) {
  // ...
} );

However it should be done, pull requests wellcome.

In this meanwhile, you can do something:

  1. Here you find the start point for this behavior
  2. It leads you here or here, depending on what your are using (hash x history).
  3. Regardless, we found ourselves here at this point, where we can dig the history array:
// pseudo code here (not tested)
var addressbar = require('ways-addressbar');
ways.use(addressbar);
ways( "/route", function( req ) {
  console.log(addressbar.history);
} );
ways.go('/route', {hi: true});

Something should be there. :)

@hems
Copy link
Author

hems commented Dec 24, 2015

i'm not using addressbar.... in that case ?

@arboleya
Copy link
Owner

In this case, following the frist link I've sent, in you're here, without history / pushstate.

You can do a plugin and make it handle state/history for you, the basics are also covered in the tests in case you wanna take a look.

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

No branches or pull requests

2 participants