[WIP][TwigComponent] add component attribute system/helper (alternative) #229
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 is an alternative to #220. This version makes attributes a primary feature (doesn't require a trait to use). In your components, an
attributes
object is always available. Properties passed to thecomponent
twig function that cannot be mounted to your component object are added to this object. This pattern is well established in blade/vue.I haven't given a huge amount of thought yet to LiveComponent's. I'm thinking the attributes passed to the twig function will be passed back and forth via http with a special proprietary attribute.
This will bring some BC breaks:
component
twig function that do not exist on your component class will no longer throw an exception. Instead they are added to theattributes
object. Since attributes are required to be string/scalar I could throw an exception if the passed extra values are not.ComponentFactory::create()
directly (unlikely scenario imo). This method now returns aComponentContext
object instead of the component object.TwigComponent
andLiveComponent
at the same time, if someone upgrades one without the other, there will be problems.These seem fairly minor to me (we are still experimental) but any ideas to mitigate the above would be appreciated!
TODO
LiveComponent
supportComponentAttributes
methodsUsage
Defaults
Set default attributes that can be fully overridden by passed attributes
Merging Defaults
Set defaults but allow them to be appended to by passing these values to the
component
function:Only
Without