Comments (9)
Yes this sort of logic is best served by a hypernova-client like hypernova-react.
A hypernova client is just a function so you can do and return whatever you'd like.
from hypernova.
That seems like something you could do by defining your own getComponent function and Component.name
from hypernova.
Ah, I've misread; you want to call a different render method based on the name of the component. This definitely seems like something you could do yourself by implementing your own renderReact
method - I'm curious what your "legacy reasons" are, but complicating APIs for legacy reasons is generally an unwise idea.
from hypernova.
Thanks for the speedy responses!
@goatslacker I might be misunderstanding things here - without changing the component name, I'm not sure how to pass down this flag from the consuming frontend server?
Just to start again to clarify:
I'd like to keep the name of the component (in our case "NameOfComponent") the same, but be able to choose between static/dynamic rendering. There are two ways I can see of doing this:
- Changing the name of the component to control this - i.e. define
NameOfComponentStatic
andNameOfComponentDynamic
and userenderReact
/renderReactStatic
as appropriate, or even a new method that encapsulates this bit of logic as suggested. This was my initial thought, but I'm not sure changing the name of the component just to pass in args seems that great? What are your thoughts on this? - Extending the API to be able to pass extra non-prop args, such as the static/dynamic flag, which gets passed alongside
name
togetComponent
.
(fwiw the legacy reasons are as part of a migration - for shared components that have been ported but shouldn't be react components yet, and so shouldn't be hydrated on the client)
Thanks for being so patient with me on this :)
from hypernova.
@ljharb @goatslacker @spikebrehm Any further thoughts on this?
from hypernova.
Can this do what you want?
const { renderReactStatic, renderReact } = require('hypernova-react')
const Component = require('/some/path/to/a/component')
const staticRender = renderReactStatic('NameOfComponent', Component)
const dynamicRender = renderReact('NameOfComponent', Component)
const renderStaticOrDynamic = isStatic => (
isStatic === true ? staticRender() : dynamicRender()
)
module.exports = renderStaticOrDynamic
from hypernova.
@goatslacker I still need a way to pass the 'isStatic' flag (amongst other server only args) through to Hypernova from the clientlib :)
(The branch I'm working on does this by passing it through the currently undocumented context arg, but it'd be nice to have a proper documented way of doing this that I can merge upstream)
from hypernova.
So we've actually come full circle on this issue
We might have potential collisions in the browser when we do renderReact(name, ...)
- if two packages both define a component of the same 'name
'. So to prevent this, we're going to namespace our components, which means we'll just go with option 1 and encode all 'server' data in the component.
from hypernova.
I still need a way to pass the 'isStatic' flag (amongst other server only args) through to Hypernova from the clientlib :)
I see, so your other server is the one that holds the knowledge on whether you want to render something static or non-static. If thats' the case you can pass that sort of information down with the initial payload:
{
renderStyle: 'static',
componentProps: serializableProps,
}
from hypernova.
Related Issues (20)
- An in-range update of glob is breaking the build 🚨 HOT 2
- Example of async component fetching
- createApplication in docs but not released HOT 4
- More details about server requirements for production HOT 1
- [Question] Runtime loading/unloading modules HOT 2
- Proper source map support for development mode HOT 8
- Ruby version in example is ambiguous HOT 3
- An in-range update of eslint-plugin-import is breaking the build 🚨 HOT 2
- [Question] Load application on demand showing a pre loading
- An in-range update of rimraf is breaking the build 🚨 HOT 3
- CSS support? HOT 12
- Custom attributes on Hypernova DOM container HOT 1
- Encode closing Tag HOT 8
- Assets support
- An in-range update of eslint-plugin-import is breaking the build 🚨 HOT 3
- This project is no longer maintain? HOT 4
- An in-range update of in-publish is breaking the build 🚨 HOT 1
- Loadable Component integration
- Will this work with rails 7.x
- missing `.finally()` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hypernova.