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
[WIP] Fix #59 - Improved Middlewares #127
[WIP] Fix #59 - Improved Middlewares #127
Conversation
I've made quick @arunoda am I heading right direction? |
_.each(self._middleware, function(fn) { | ||
self._page("*", fn); | ||
|
||
self._page('*', function(ctx, next) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for running this in a different page middleware and differ it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no reason, just experiment. Moved to initialize
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay :)
Yep. You are on the right track :) |
@arunoda I've just added exit triggers support. Can you quickly glance through it? Thanks. |
self._page("*", function(ctx, next) { | ||
_.each(self._triggersEnter, function(fn) { | ||
if (typeof fn === 'function') { | ||
fn(ctx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ctx
should be ._current
.
It should be the same for others as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean calling every triggers with self._current
like fn(self._current)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
On Thu, May 28, 2015 at 2:45 PM Delgermurun Purevkhuu <
notifications@github.com> wrote:
In client/router.js
#127 (comment)
:self._page.callbacks = [];
- self._page.exits = [];
- // add global enter triggers
- self._page("*", function(ctx, next) {
- _.each(self._triggersEnter, function(fn) {
if (typeof fn === 'function') {
fn(ctx);
Do you mean calling every triggers with self._current like
fn(self._current)?—
Reply to this email directly or view it on GitHub
https://github.com/meteorhacks/flow-router/pull/127/files#r31215724.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But _current
is empty ({}
) on global triggersEnter
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we call triggersEnter inside our main tracker rather than, doing it inside `page(*)
see: https://github.com/delgermurun/flow-router/blob/improved-middlewares/client/router.js#L313
@arunoda updated. |
_.each(self._middleware, function(fn) { | ||
self._page("*", fn); | ||
}); | ||
|
||
_.each(self._routes, function(route) { | ||
self._page(route.path, route._handler); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be we can isolate this into a seperate function.
Overall this looks great to me. |
Today I'll implement |
Superb.
|
@arunoda P.S: Sorry for interrupting too much :) |
return false; | ||
} | ||
|
||
if (!name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one affect to the only logic. So, even if it's only for one route
It's possible to call unnamed routes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How should we declare only
for this case? only: ['']
, only:[]
or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I understand incorrectly. Ignore above comment.
I just realized there is bug, sorry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)
Does It looks so ugly. |
I don't think so. For if statements it's okay. |
@@ -369,3 +427,56 @@ Router.prototype._updateCallbacks = function () { | |||
|
|||
Router.prototype._page = page; | |||
Router.prototype._qs = qs; | |||
|
|||
function shouldCallTrigger(current, fn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can create these as methods in the Router class. Then we can test them individually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did that because of I don't want to make bigger Router class. How does it affect performance?
Don't we have other way to test :)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've other ways to test.
If you feel router getting bigger, try to move them to a util namespace.
I really don't like to have private methods hidden inside like this.
(I sometimes do it although if I were lazy)
@arunoda updated. Regarding class size, yeah it feels bigger. But let's just create method. Later we can improve. |
This implementation looks good to me. I didn't catch your last comment. Sorry for that. |
@arunoda no problem, I'm glad that you liked it :D. I'm going to push tests tomorrow. |
Awesome :) On Tue, Jun 2, 2015 at 4:19 PM Delgermurun Purevkhuu <
|
@arunoda added tests. |
I think test cases covers all the cases (or at least most of the cases) |
Awesome. |
Oh. Should I rebase it? @arunoda |
I don't think there are any conflicting changes. If you like, rebase squash it. |
I mean "sqaushing" and sqaushed :D |
Yeah :)
|
next(); | ||
}, 0); | ||
this._triggersEnter.push(function(ctx) { | ||
var str = location.search.slice(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here we can't depend on the location
. I think right now, location is not yet changed?
Quite not sure, I'll check.
Edit: I think, I might be wrong, since now we are not depends on pagejs middleware for this
@delgermurun don't do any changes I requested. I simply did them :) |
@arunoda okay. Thanks. |
@arunoda Oh, one thing to mention. How did you refactor |
I did this in place where we set |
Okay. You already noticed that :). |
I manually took the PR. It's alive. |
|
Add support for #59