-
Notifications
You must be signed in to change notification settings - Fork 208
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
Allow subscription to just a *param* in the hash changing #16
Comments
Yeah, I am no longer satisfied with JavaScriptMVC's approach to history, so I want to make bbq part of how history is used. I really like sammy's routing: get('#/by_name/:name', function() { BUT!!!! I think this would be even better if this was natural as listening to an event. I'd have to check if jQuery setup / init can do this, but: $(window).bind("hashchange.bbq1", function(ev, params){ }) would be frankly disgustingly sick |
The API should be as jQuery-like as possible (and as BBQ-like as possible), so I'm thinking something like:
And this:
In the latter, I think the handler should execute once for each param, so if both 'a' and 'b' change in a single hashchange event, the event handler will fire twice. Make sense? I'm totally open to ideas. I'd really like to nail this out of the gate, though. |
Another idea that Paul Irish likes that's worth noting:
This could be used to simulate routes (also, value could be a RegExp). |
Ah, I was thinking about that yesterday too. I was also thinking about 'fancy' routes. "#/:a/options" I'm not sure how that would work. Also, what do you think about the event getting back a second argument which is params? I suppose you don't always want to calculate it. |
I wouldn't add additional arguments to the callback, but instead add properties or methods to the already-passed event object. The param could be Enabling full-on routes could be handled by a more route-centric addon on top of BBQ, I don't think it should be in the core (at least, not for now). |
I always feel a little dirty adding expandos to events, even if they are jQuery.Event. |
I'm ok if you have an option to do routes style dispatching via an addon, however for large scale projects, object based dispatching works so much better. (I work on a project who's routes based dispatching builds a regexp 16KB long. Yuck.) |
Ok, what about this API idea?
|
For the data=['a', 'b', 'c'] and data={ a: 'x', b: 'y', c: /./ } cases, I would want a single event fired on a match of all params, and not once per each parameter that matches. For example, if I had a tab widget inside an accordion, I would want to set var 'a' for the state of the accordion, and var 'b' for the state of the tab. I'd use a data = {a: 'tabpage', b: /./} to subscribe to the hashchange event. Then if the accordion is on a page that the tab widget is not displayed on, then it doesn't get the event, but if if the accordion displays the "tabpage", any change in 'b' will trigger the event, but only once. It'd be a way to filter the events that are relevant. All of that said, I'm having a hard time figuring out how that would work with JavascriptMVC where hashchange events are currently translated into a OpenAJAX hub event. This, I guess, is why Justin was pushing for a regex based routes system that uses a data type (string) that can be used directly as an OpenAJAX event name. However, I can imagine a scenario where you have thousands of regexes being run on every hash change, and worry about performance. Maybe jQuery/JSMVC event dispatching is somehow smarter than that, I don't know much about it. |
Justin's idea http://twitter.com/justinbmeyer/status/22037575805 and very cool.
The text was updated successfully, but these errors were encountered: