arboleya / ways

Fluid router specially designed for complex page transitions and granular UI animations
MIT License
30 stars 2 forks source link

retrieving the current request "state" ? #7

Open hems opened 8 years ago

hems commented 8 years ago

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 commented 8 years ago

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

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 commented 8 years ago

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

arboleya commented 8 years ago

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.