-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Try: Components decorator extensibility pattern #1023
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aduth
added
Framework
Issues related to broader framework topics, especially as it relates to javascript
[Status] In Progress
Tracking issues with work in progress
labels
Jun 5, 2017
Mmm, good exploration, here are some initial thought/questions:
Awesome job ❤️ |
2 tasks
gziolo
reviewed
Nov 9, 2017
uid: ownProps.uid, | ||
} ); | ||
export default flow( | ||
applyComponentDecorators, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is exactly what we need to Collaborative Editing to be able to display a different UI state when collaborator is editing the block 👍
1 task
Closing for now as satisfied by #3318. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Framework
Issues related to broader framework topics, especially as it relates to javascript
[Status] In Progress
Tracking issues with work in progress
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.
Experimental: These changes are highly incomplete, unpolished, and break nearly as much functionality as they introduce.
This pull request seeks to explore a decorator pattern for extensibility. It is primarily composed of two parts:
applyDecorators
, a higher-order component that flags a component as being enabled to accept decorators, responsible for managing the extensions during render.registerExtension
, the API by which extensions can hook to component rendering via adecorators
property, an array of tuples where the first entry is the component to hook and the second entry a higher-order component to dynamically introduce to the wrapped component's rendering flowSee included
wide-align
usageThe use-case explored was that of wide image rendering, which is unique in that it depends on a relationship between two components: The
Layout
component for accessing the available width of the editor canvas, and theVisualEditorBlock
component for applying the margin offsets. To achieve this I'd first explored using Reactcontext
to pass information from the Layout decorator to the VisualEditorBlock component, but found that React-Redux's pure-by-default nature had the undesirable side-effect of preventing context changes from being reflected in the descendant component (#2517).Instead I landed on the idea of namespaced extension state to be shared between all component decorators registered by
registerExtension
. A component decorator can interact with it usingextensionState
andsetExtensionState
from props (similar in usage tosetState
orsetAttributes
).The approach differs from react-slot-fill in that a slot can be occupied by one or more fill to be rendered as a child, whereas a decorator wraps the original component and has power to replace or augment the original render behavior. I've not yet settled on whether the decorator pattern could serve as a complete replacement for slot/fill, or if the two complement each other in their own independent purpose. If slots were to remain, I think it could fit well within the existing API via
registerExtension( { slots: { slotName: [ fillOne, fillTwo ] } } );
.Testing instructions:
As noted, there is breakage resulting from these changes, notably floated content. Observe though that Wide alignment (image, video, etc) stretches to occupy the full width.