Skip to content

refactor: 💡 Add options to the "call" middleware #17

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

Merged
merged 1 commit into from
Mar 27, 2019
Merged

refactor: 💡 Add options to the "call" middleware #17

merged 1 commit into from
Mar 27, 2019

Conversation

toerndev
Copy link
Contributor

@toerndev toerndev commented Feb 6, 2019

"call" now needs the new options "runOnServer", "runOnHydrate" to be
passed explicitly, rather than using hard-coded logic to determine where
to run.
"runOnClientRender" has not been added since there's currently no
use-case for skipping client render.

This aims to clarify when each callback runs.

Copy link
Collaborator

@hedgepigdaniel hedgepigdaniel left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

I think the CI is failing for unrelated reasons (Snyk is not free). Once we fix that I think we can merge this.

Maybe with this we can make a simple example of reducer splitting with SSR aswell...

import { isHydrate } from '../../../utils'

export default (name, route, req) => {
export default (name, route, req, { runOnServer, runOnHydrate }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you think its a good idea to make the default behaviour that it runs on the server and not hydrate? Seems like usually people want callbacks to happen at least at some point on initial load.

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 can't really visualize the use-case for these from the end-users POV, as I haven't used SSR personally. However I do think that skipOnServer (+ reversing logic in shouldCall) is a better API than runOnServer = true in that case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I like that both options have the same positive polarity (runOnX + skipOnY I think is more confusing) but potentially one could default to true?

Copy link
Contributor Author

@toerndev toerndev Feb 6, 2019

Choose a reason for hiding this comment

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

I agree that it's confusing, but implicit true seems even worse. :-)
Undefined is false in JS so it's easy to see when an option is not set. If we change that, it suddenly becomes hard to know whether it's required to say "fooFlag: false" or "barFlag: true", and it somehow becomes a tristate.
Is there a third option?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I forget which babel plugin its in, but I think I've seen code like

(name, route, req, { runOnServer = true, runOnHydrate = false }) => {}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't worry though, I think its fine the way it is, simple and clear.

@ScriptedAlchemy
Copy link
Member

Howdy, beeen out the loop for a while. Ill review this tomorrow. Thank you for this!!!

@hedgepigdaniel
Copy link
Collaborator

I've rebased this branch on master but it seems that that is not enough to make Snyk happy...

"call" now needs the new options "runOnServer", "runOnHydrate" to be
passed explicitly, rather than using hard-coded logic to determine where
to run.
"runOnClientRender" has not been added since there's currently no
use-case for skipping client render.

This aims to clarify when each callback runs.
@hedgepigdaniel
Copy link
Collaborator

Turns out the tests were failing because of jestjs/jest#8069

Travis updated their node now 🎉

@hedgepigdaniel hedgepigdaniel merged commit 3492cac into respond-framework:master Mar 27, 2019
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.

3 participants