[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) { |
arunoda
May 27, 2015
Contributor
Any reason for running this in a different page middleware and differ it?
Any reason for running this in a different page middleware and differ it?
delgermurun
May 27, 2015
Author
Contributor
There is no reason, just experiment. Moved to initialize
.
There is no reason, just experiment. Moved to initialize
.
arunoda
May 27, 2015
Contributor
Okay :)
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); |
arunoda
May 28, 2015
Contributor
This ctx
should be ._current
.
It should be the same for others as well.
This ctx
should be ._current
.
It should be the same for others as well.
delgermurun
May 28, 2015
Author
Contributor
Do you mean calling every triggers with self._current
like fn(self._current)
?
Do you mean calling every triggers with self._current
like fn(self._current)
?
arunoda
May 28, 2015
Contributor
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.
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.
delgermurun
May 28, 2015
Author
Contributor
But _current
is empty ({}
) on global triggersEnter
?
But _current
is empty ({}
) on global triggersEnter
?
arunoda
May 28, 2015
Contributor
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
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
}); | ||
|
||
// add global exit triggers | ||
self._page.exit("*", function(ctx, next) { |
arunoda
May 28, 2015
Contributor
updateCallback
function seems pretty lengthy now. How abotu moving breaking these into multiple functions. We can write it like this.
...
self._page("*", self._processTriggersBefore.bind(self))
self._page.exit("*", self._processTriggersExit.bind(self))
...
updateCallback
function seems pretty lengthy now. How abotu moving breaking these into multiple functions. We can write it like this.
...
self._page("*", self._processTriggersBefore.bind(self))
self._page.exit("*", self._processTriggersExit.bind(self))
...
@arunoda updated. |
_.each(self._middleware, function(fn) { | ||
self._page("*", fn); | ||
}); | ||
|
||
_.each(self._routes, function(route) { | ||
self._page(route.path, route._handler); | ||
|
arunoda
May 28, 2015
Contributor
May be we can isolate this into a seperate function.
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) { |
arunoda
May 29, 2015
Contributor
This one affect to the only logic. So, even if it's only for one route
It's possible to call unnamed routes.
This one affect to the only logic. So, even if it's only for one route
It's possible to call unnamed routes.
delgermurun
May 29, 2015
Author
Contributor
How should we declare only
for this case? only: ['']
, only:[]
or something else?
How should we declare only
for this case? only: ['']
, only:[]
or something else?
delgermurun
May 29, 2015
Author
Contributor
Oh, I understand incorrectly. Ignore above comment.
I just realized there is bug, sorry.
Oh, I understand incorrectly. Ignore above comment.
I just realized there is bug, sorry.
arunoda
May 29, 2015
Contributor
:)
:)
return true; | ||
} | ||
|
||
if (!!fn._only && _.indexOf(fn._only, name) === -1) { |
arunoda
May 29, 2015
Contributor
It's better if we can create a map based on only and except routes
at the beginning.
Then we don't need to use indexOf.
Not only about a performance issue. It's easy to read without it.
It's better if we can create a map based on only and except routes
at the beginning.
Then we don't need to use indexOf.
Not only about a performance issue. It's easy to read without it.
delgermurun
May 29, 2015
Author
Contributor
created maps
created maps
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) { |
arunoda
May 29, 2015
Contributor
You can create these as methods in the Router class. Then we can test them individually.
You can create these as methods in the Router class. Then we can test them individually.
delgermurun
May 29, 2015
Author
Contributor
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 :)?
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 :)?
arunoda
May 29, 2015
Contributor
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)
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)
return true; | ||
} | ||
|
||
function getRegisterTriggersFn(triggers) { |
arunoda
May 29, 2015
Contributor
Same as above
Same as above
return false; | ||
} | ||
|
||
if (!fn._only && !name) { |
arunoda
May 29, 2015
Contributor
How about if we branch these multiples ifs into three.
if(fn._only) {
// ...
} else if(fn._except) {
// ...
} else {
// ...
}
For my small brain, it's super hard to read this logic :)
How about if we branch these multiples ifs into three.
if(fn._only) {
// ...
} else if(fn._except) {
// ...
} else {
// ...
}
For my small brain, it's super hard to read this logic :)
delgermurun
May 29, 2015
Author
Contributor
good idea :)
good idea :)
@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); |
arunoda
Jun 4, 2015
Contributor
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
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
self._page.exits = []; | ||
|
||
self._page("*", function(ctx, next) { | ||
var str = location.search.slice(1); |
arunoda
Jun 4, 2015
Contributor
Why two places processing qs?
Why two places processing qs?
delgermurun
Jun 4, 2015
Author
Contributor
Oh, I forgot to delete it.
Oh, I forgot to delete it.
_.each(self._middleware, function(fn) { | ||
self._page("*", fn); | ||
}); | ||
|
||
_.each(self._routes, function(route) { | ||
self._page(route.path, route._handler); | ||
self._processRouteTriggersExit(route); |
arunoda
Jun 4, 2015
Contributor
I think this function should be _registerRouteTriggersExit
I think this function should be _registerRouteTriggersExit
@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