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

[WIP] Fix #59 - Improved Middlewares #127

Closed
wants to merge 1 commit into from
Closed

[WIP] Fix #59 - Improved Middlewares #127

wants to merge 1 commit into from

Conversation

delgermurun
Copy link
Contributor

Add support for #59

@delgermurun
Copy link
Contributor Author

I've made quick middleware => triggersEnter change.

@arunoda am I heading right direction?

_.each(self._middleware, function(fn) {
self._page("*", fn);

self._page('*', function(ctx, next) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay :)

@arunoda
Copy link
Contributor

arunoda commented May 27, 2015

Yep. You are on the right track :)
For now, we need to keep the middleware API as it is until we release 2.0

@delgermurun
Copy link
Contributor Author

@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);
Copy link
Contributor

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.

Copy link
Contributor Author

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)?

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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

@delgermurun
Copy link
Contributor Author

@arunoda updated.

_.each(self._middleware, function(fn) {
self._page("*", fn);
});

_.each(self._routes, function(route) {
self._page(route.path, route._handler);

Copy link
Contributor

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.

@arunoda
Copy link
Contributor

arunoda commented May 28, 2015

Overall this looks great to me.
But I didnt try it out locally.
Let's have some tests too.

@delgermurun
Copy link
Contributor Author

Today I'll implement only and except. Then I'm going to add tests.

@arunoda
Copy link
Contributor

arunoda commented May 28, 2015

Superb.
On 2015 මැයි 29, සිකු at පෙ.ව. 4.20 Delgermurun Purevkhuu <
notifications@github.com> wrote:

Today I'll implement only and except. Then I'm going to add tests.


Reply to this email directly or view it on GitHub
#127 (comment)
.

@delgermurun
Copy link
Contributor Author

@arunoda only and except support added. Please check this out.

P.S: Sorry for interrupting too much :)

return false;
}

if (!name) {
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

@delgermurun
Copy link
Contributor Author

Does !! need on if statement (maybe for performance)? I guess I've read something about it, but can't remember exactly.

It looks so ugly.

@arunoda
Copy link
Contributor

arunoda commented May 29, 2015

I don't think so. For if statements it's okay.
You may need to do it if you really need to send a boolean

@@ -369,3 +427,56 @@ Router.prototype._updateCallbacks = function () {

Router.prototype._page = page;
Router.prototype._qs = qs;

function shouldCallTrigger(current, fn) {
Copy link
Contributor

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.

Copy link
Contributor Author

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 :)?

Copy link
Contributor

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)

@delgermurun
Copy link
Contributor Author

@arunoda updated.

Regarding class size, yeah it feels bigger. But let's just create method. Later we can improve.

@arunoda
Copy link
Contributor

arunoda commented Jun 2, 2015

This implementation looks good to me. I didn't catch your last comment. Sorry for that.
When we can see tests :)
I'm eager to push this into a release.

@delgermurun
Copy link
Contributor Author

@arunoda no problem, I'm glad that you liked it :D.

I'm going to push tests tomorrow.

@arunoda
Copy link
Contributor

arunoda commented Jun 2, 2015

Awesome :)

On Tue, Jun 2, 2015 at 4:19 PM Delgermurun Purevkhuu <
notifications@github.com> wrote:

@arunoda https://github.com/arunoda no problem, I'm glad that you liked
it :D.

I'm going to push tests tomorrow.


Reply to this email directly or view it on GitHub
#127 (comment)
.

@delgermurun
Copy link
Contributor Author

@arunoda added tests.

@arunoda
Copy link
Contributor

arunoda commented Jun 3, 2015

I think test cases covers all the cases (or at least most of the cases)
I'll do a full code review again and get this PR.

@delgermurun
Copy link
Contributor Author

Awesome.

@delgermurun
Copy link
Contributor Author

Oh. Should I rebase it? @arunoda

@arunoda
Copy link
Contributor

arunoda commented Jun 3, 2015

I don't think there are any conflicting changes. If you like, rebase squash it.

@delgermurun
Copy link
Contributor Author

I mean "sqaushing" and sqaushed :D

@arunoda
Copy link
Contributor

arunoda commented Jun 3, 2015

Yeah :)
On 2015 ජූනි 3, බදාදා at පෙ.ව. 11.26 Delgermurun Purevkhuu <
notifications@github.com> wrote:

I mean "sqaushing" and sqaushed :D


Reply to this email directly or view it on GitHub
#127 (comment)
.

next();
}, 0);
this._triggersEnter.push(function(ctx) {
var str = location.search.slice(1);
Copy link
Contributor

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

@arunoda
Copy link
Contributor

arunoda commented Jun 4, 2015

@delgermurun don't do any changes I requested. I simply did them :)

@delgermurun
Copy link
Contributor Author

@arunoda okay. Thanks.

@delgermurun
Copy link
Contributor Author

@arunoda Oh, one thing to mention. How did you refactor ctx.params.query = self._qs.parse(str); section. It inserts on last of the global enter triggers. I think we should move it to contructor function.

@arunoda
Copy link
Contributor

arunoda commented Jun 4, 2015

I did this in place where we set _current. here: https://goo.gl/jrqwgi

@delgermurun
Copy link
Contributor Author

Okay. You already noticed that :).

@arunoda
Copy link
Contributor

arunoda commented Jun 4, 2015

I manually took the PR. It's alive.

@arunoda arunoda closed this Jun 4, 2015
@delgermurun
Copy link
Contributor Author

🎉

@delgermurun delgermurun deleted the improved-middlewares branch June 4, 2015 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants