Major Update: Add renderers to handle story displaying logic #80
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR includes changes to the way a story is displayed inside the component container. Due to several issues being raised for unpredictable loading states, race issues in the progress bar, this looks like a good solution to isolate the rendering of content by providing necessary properties to it.
The renderer logic is heavily inspired by the open-source project JSON Forms.
The logic works as follows:
renderer
according to various conditions exposed by the renderer.renderer
property which is a functional component and atester
which is a function.tester
function and returns the first one that matches the condition.renderers
.In all, it affects the internal working in the following ways:
Use renderers internally
All the hacky, conditional logic to check what to render in the story container has been replaced by internal default renderers for image and video. Custom content remains untouched due to this - if the
content
prop in the story object is not undefined, then the value of thecontent
prop will be the renderer by default.Possible to create re-usable renderers
Similar to any other plugin system, this creates a possibility to create shared renderers. If you build one, you can host it on a public registry like
npm
and let others use it directly.Expose
WithHeader
andWithSeeMore
as named exportsNow the package would also include these two named exports so that one can directly use the header/see more functionality when creating custom content.
Breaking⚠️ Since the rendering is now isolated to renderers, whenever a story changes, the progress would pause by default. Till now, there was a check written internally that if a custom content is sent, the progress should start playing immediately. But now this behaviour would be inconsistent.There will be no breaking changes and this will be a 2.1.0 release.
I believe this change would help increase the customisability of this component. Do let me know if you have any suggestions, I plan to merge this PR in a few days if everything looks good. You can join the Discord server here.