You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Today, whyframe only handles component isolation side of things, which is good for specific tasks, but if you need more from it it'll involve a lot of work. For example:
Clicking a button in a frame, we want to show the event logs.
Change props for the button, we want a control panel that automatically detect the button props and allow us to customize in the browser.
iframe keys are introduced as a way to link itself with another component seamlessly. It needs to be static so it can be analyzed to generate the necessary code to pass metadata to the component. It needs to be unique within that file only.
This also opens up the whyframe:metadata:some-unique-id module so raw source can be imported and rendered in SSR. Plus the potential of providing metadata that can't be serialized as an attribute. (Previously whyframe would inject the raw source into the iframe internal data-why-source attribute)
The control panel and event log can also take advantage of the key to prevent boilerplate when passing metadata between them and the iframe. This also allows them to have direct communication to the iframe to send fine-grained update events.
Implementation
Deprecate the old way of handling source.
Implement iframe keys. Optional only. This would break the Astro plugin convention but luckily not many are using it.
Implement metadata API for each framework. This would be the hardest but previewjs did a great job supporting this so far. Investigate if this can be done as a pure Vite plugin.
Implement control panels and event logs as a custom element. Create framework-specific wrapper. The libraries need to register with @whyframe/core to inform @whyframe/svelte, @whyframe/vue, and @whyframe/jsx how to handle these special components. The API will be a contract between the special components and @whyframe/core.
Settle on a control API if other libraries intend to build an alternative. The target: '$ > div[class]' property may need further design thoughts, but this will allow a generic way to target elements with the iframe, and allow whyframe to surgically update the application state instead of re-rendering everything. Same goes to events API.
Notes
If possible, make sure the special components implementation is generic enough that someone could technically implement all by themselves today with the only downside of boilerplate, which whyframe only providing syntax sugar.
Alternatives
Hooks
It's also important to think of the API in the framework's natural pattern. In React and Vue, hooks are more commonly used. It may look like:
The issue is that since the API is runtime, it's harder to treeshake things. For example, you can't treeshake the raw source unless we implement useWhyframe({ rawSource: true }).
iframe variable also implies that we can forward it down to the children, but if that happens the compilation wouldn't be able to know which exact iframe element to process.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
TLDR: See "Proposal" section
Today,
whyframe
only handles component isolation side of things, which is good for specific tasks, but if you need more from it it'll involve a lot of work. For example:Proposal
iframe keys
Optional:
Import metadata via key
Framework component metadata API
Control panel
Basic:
Modify:
Configure:
Event log
Explanation
iframe keys are introduced as a way to link itself with another component seamlessly. It needs to be static so it can be analyzed to generate the necessary code to pass metadata to the component. It needs to be unique within that file only.
This also opens up the
whyframe:metadata:some-unique-id
module so raw source can be imported and rendered in SSR. Plus the potential of providing metadata that can't be serialized as an attribute. (Previouslywhyframe
would inject the raw source into theiframe
internaldata-why-source
attribute)The control panel and event log can also take advantage of the key to prevent boilerplate when passing metadata between them and the
iframe
. This also allows them to have direct communication to theiframe
to send fine-grained update events.Implementation
Deprecate the old way of handling source.
Implement iframe keys. Optional only. This would break the Astro plugin convention but luckily not many are using it.
Implement metadata API for each framework. This would be the hardest but previewjs did a great job supporting this so far. Investigate if this can be done as a pure Vite plugin.
Implement control panels and event logs as a custom element. Create framework-specific wrapper. The libraries need to register with
@whyframe/core
to inform@whyframe/svelte
,@whyframe/vue
, and@whyframe/jsx
how to handle these special components. The API will be a contract between the special components and@whyframe/core
.Settle on a control API if other libraries intend to build an alternative. The
target: '$ > div[class]'
property may need further design thoughts, but this will allow a generic way to target elements with the iframe, and allowwhyframe
to surgically update the application state instead of re-rendering everything. Same goes to events API.Notes
If possible, make sure the special components implementation is generic enough that someone could technically implement all by themselves today with the only downside of boilerplate, which
whyframe
only providing syntax sugar.Alternatives
Hooks
It's also important to think of the API in the framework's natural pattern. In React and Vue, hooks are more commonly used. It may look like:
The issue is that since the API is runtime, it's harder to treeshake things. For example, you can't treeshake the raw source unless we implement
useWhyframe({ rawSource: true })
.iframe
variable also implies that we can forward it down to the children, but if that happens the compilation wouldn't be able to know which exactiframe
element to process.Beta Was this translation helpful? Give feedback.
All reactions