Dot notation data props - #218
Conversation
…op demo for better testing. Includes an array for checkboxes.
There was a problem hiding this comment.
Pull Request Overview
This PR adds server-side support for dot notation data properties in Livewire components, enabling developers to use nested property references like user.name.first in wire:model attributes. The implementation leverages CFML's native structGet() function for retrieving nested values and introduces a new _updateDataValue() function for setting nested property values.
Key changes include:
- Enhanced
_applyUpdates()function to handle dot notation property updates - New
_updateDataValue()helper function for safely setting nested property values - Updated lifecycle event naming for nested properties (dots converted to underscores)
Reviewed Changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| models/Component.cfc | Core implementation of dot notation support with new helper function |
| test-harness/tests/specs/CBWIRESpec.cfc | Three new test cases validating dot notation functionality |
| test-harness/wires/workshop/NestedDataKeys.* | Example workshop component demonstrating nested data usage |
| test-harness/server-adobe@*.json | Server configuration updates for ACF compatibility |
| test-harness/layouts/workshop.cfm | Navigation link added for new example |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
grantcopley
left a comment
There was a problem hiding this comment.
@mrigsby I've pulled this down and tested it and everything seems to be working well. Fantastic work! Merging.
Livewire.js already supports dot notation for data properties on the client. This adds server functionality to handle those dot notation keys in your wire.
For Example:
YourWire.cfc Data properties
YourWire.cfm inputs with wire:model
Changes/Additions
changes to
_applyUpdates( updates )function ( models/Component.cfc )structGet()to retrieve values from data properties since it already supports got notation_updateDataValue()function to update data property valuesNote for OnUdpate[ Property ] LifeCycle Events:
Creates
onUpdate[ Property ]lifecycle events for nested keys by changing dots to underscores, thus theonUpdate[ Property ]lifecycle event foruser.name.firstwould beonUpdateuser_name_first( newValue, oldValue )Added
_updateDataValue( keyPath, value )function ( models/Component.cfc )keyPath&valueuser.address.zip) and single depth keys (i.e.roles)keyPathargument into an array (if not dot notation it is a single value array) and loops over the array of keys to traverse the data properties to get to the target data property and sets the value to the providedvalueargumentTestBox Tests
Adds three tests for functionality. As a note, all other tests are now also using
structGet()for retrieval of data properties and_updateDataValue( keyPath, value )for setting data properties.should provide updates to data properties using dot notationshould support incoming array values in dot notation referenced arrayshould call onUpdate[Property_Dot_Notation] if it existsAdded Example
Adds an example wire in the Workshop examples used for the ITB 2024 workshop found at
http://127.0.0.1:60299/workshopwhen the test-harness servers are run. This example uses multiple nested data property keys as well as a nested array for checkboxes.Other Minor Changes
.gitignore
views/tmp/**since the test harness created a handful of temporary view files it wanted to include in the commits.DS_Storesince I work on a mac and it wanted to include all these auto created on my macServer .json files Updates for ACF
zippackage and errors until installed. I added the CFPM entry to install this on startup