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

Pre-Render Hook #623

Open
jonwinton opened this issue Dec 13, 2018 · 2 comments
Open

Pre-Render Hook #623

jonwinton opened this issue Dec 13, 2018 · 2 comments

Comments

@jonwinton
Copy link
Contributor

jonwinton commented Dec 13, 2018

Idea: preRender hook in model.js

Purpose: Sets context of request by providing a context specific object which components can attach data to. This would then be passed into the render function to basically allow context specific data to be shared across components.

Good use case: we want specific ad injection logic defined on the layout level to be respected by an article. A component in the layout contains the specification of the logic, attaches it to ctx, and then the article can read it. Also ,maybe some dedupe logic in feeds?

Example:

module.exports.beforeRender = (uri, data) => {
    return {foo: 'bar'};
}

module.exports.render = (uri, data, locals, ctx) => {
    data.foo = ctx.foo;
    return data;
}

Not settled, but just putting something down.

@jonwinton
Copy link
Contributor Author

Updating this for the naming. Should be called beforeRender.

"also minor side point: I think beforeRender is a better name because it's a more conventional name for a lifecycle hook; prerender is a verb; before/after/on are events" - @rmfarrell

@jonwinton
Copy link
Contributor Author

Testing this in Amphora now and will post the branch when it's ready.

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

No branches or pull requests

1 participant