Skip to content

Support for global view context#6

Merged
arb merged 3 commits intohapijs:masterfrom
jagoda:feat-global-context
Oct 31, 2014
Merged

Support for global view context#6
arb merged 3 commits intohapijs:masterfrom
jagoda:feat-global-context

Conversation

@jagoda
Copy link
Copy Markdown
Contributor

@jagoda jagoda commented Oct 30, 2014

Closes #4

@hueniverse hueniverse added the feature New functionality or improvement label Oct 30, 2014
lib/index.js Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What happens if this._context is a function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not supported in this form. I wasn't able to find a good way to make this work with the examples using the request argument.

@arb
Copy link
Copy Markdown
Contributor

arb commented Oct 30, 2014

I think maybe if they pass a function for the global context, it shouldn't take any parameters, that way it isn't limited to where it's used. If they need something from the request, they'll have it "on hand" when they call reply.view right?

@jagoda
Copy link
Copy Markdown
Contributor Author

jagoda commented Oct 30, 2014

Agreed, that will simplify things a bit. Will update accordingly. Thanks for the feedback!

@jagoda jagoda force-pushed the feat-global-context branch from 579c9af to c633aa7 Compare October 30, 2014 15:22
@jagoda
Copy link
Copy Markdown
Contributor Author

jagoda commented Oct 30, 2014

Better?

@arb
Copy link
Copy Markdown
Contributor

arb commented Oct 30, 2014

So I noticed your tests pass query in the context, can you also add a test showing what happens if you've got a query in the path as well as in the global context? Which one can the user expect to be the "winner" in that case?

@jagoda
Copy link
Copy Markdown
Contributor Author

jagoda commented Oct 30, 2014

Sure. If I understand correctly, that only applies to the Vision.handler case, right?

@arb
Copy link
Copy Markdown
Contributor

arb commented Oct 30, 2014

Anywhere were you have access to like the query string or route params. I think that's probably only in Vision.handler, but verify.

@jagoda
Copy link
Copy Markdown
Contributor Author

jagoda commented Oct 30, 2014

Vision.handler does indeed seem to be the only place where request specific artifacts are available. I have added test cases for the relevant cases. The order of precedence (highest to lowest) is:

  1. custom handler context
  2. route parameters (default handler context)
  3. global context

This seems consistent with what I saw in the existing code/tests.

@arb
Copy link
Copy Markdown
Contributor

arb commented Oct 30, 2014

@jagoda somewhere where you do server.inject pass something in the query string. We are trying to test https://github.com/hapijs/vision/blob/master/lib/index.js#L433-L446 to prove what you are saying. We want to engage the hapi code that creates request.query and make sure that it overrides the potential collision with the global context query object.

You'll want to inject a request with a query string and not pass a query as a context value. Make sense?

@jagoda
Copy link
Copy Markdown
Contributor Author

jagoda commented Oct 30, 2014

Yup, understood. I believe I did that here. Sorry if it was unclear that I added a new commit with my previous comment.

@arb arb added this to the 1.2.0 milestone Oct 31, 2014
arb added a commit that referenced this pull request Oct 31, 2014
Support for global view context
@arb arb merged commit 7c4b64e into hapijs:master Oct 31, 2014
@arb
Copy link
Copy Markdown
Contributor

arb commented Oct 31, 2014

Thanks @jagoda!

@gergoerdosi
Copy link
Copy Markdown
Contributor

@jagoda The "Global context" section in the view tutorial should be updated too: http://hapijs.com/tutorials/views#global-context

@arb
Copy link
Copy Markdown
Contributor

arb commented Oct 31, 2014

Should hold off on any documentation updates until the new version is published AND hapi uses it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This block should be a single line statement.

var defaultContext = (this._context ? (typeof this._context === 'function' ? this._context() : Hoek.clone(this._context)) : {});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK. Is there something in the style guide that I missed that applies to this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nope. just cleaner and most consistent.

@jagoda jagoda mentioned this pull request Nov 1, 2014
@jagoda
Copy link
Copy Markdown
Contributor Author

jagoda commented Nov 1, 2014

@arb no problem. I'm happy to help with documentation when the time comes. @hueniverse I opened #7 to address the style issues.

@hueniverse
Copy link
Copy Markdown
Contributor

Feel free to open a PR on hapi with the updated doc and detailed change in the issue notes. The PR should include the change to package.json as well as npm-shrinkwrap.json.

@jagoda
Copy link
Copy Markdown
Contributor Author

jagoda commented Nov 3, 2014

I'd be happy to help with the PR on Hapi once 1.2.0 is published.

@hueniverse
Copy link
Copy Markdown
Contributor

I need to fix master to remove the hapi 8 stuff I got in there by accident...

@lock
Copy link
Copy Markdown

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

feature New functionality or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Global View Context

4 participants