Repository navigation
Conversation
Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
| set value(v) { this._value = +v || 0; this.shadowRoot.querySelector('output').textContent = '' + this._value } | ||
| connectedCallback() { | ||
| this.shadowRoot.querySelector('button').onclick = () => this.dispatchEvent(new CustomEvent('step-picked', { detail: { step: this._value + 1 } })) | ||
| this.shadowRoot.querySelector('button').onclick = () => { this._value += 1; this.shadowRoot.querySelector('output').textContent = '' + this._value; this.dispatchEvent(new CustomEvent('step-picked', { detail: { step: this._value } })) } |
There was a problem hiding this comment.
Why do we need this code? Can we use the dmax for that?
There was a problem hiding this comment.
Good point. The manual _value mutation and textContent update are now replaced with a call to this.value = this._value + 1, which reuses the existing value setter that already handles both. The dmax binding data-m-ex:.@wc-step will also drive the setter when the wc-step store updates (via the wc-picked feedback binding), keeping everything in sync.
Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
| set value(v) { this._value = +v || 0; this.shadowRoot.querySelector('output').textContent = '' + this._value } | ||
| connectedCallback() { | ||
| this.shadowRoot.querySelector('button').onclick = () => this.dispatchEvent(new CustomEvent('step-picked', { detail: { step: this._value + 1 } })) | ||
| this.shadowRoot.querySelector('button').onclick = () => { this.value = this._value + 1; this.dispatchEvent(new CustomEvent('step-picked', { detail: { step: this._value } })) } |
There was a problem hiding this comment.
Why do we need value increment logic here and the custom event at all?
Can't we just use ^inc ?
| </p> | ||
| <p>Current hash: <span id="hashOut" data-m-ex:.@_init@_window.hashchange^.location.hash="val || '#'"></span></p> | ||
| <mx-step id="wcStep" data-m-ex:.@wc-step="'' + val" data-m-ex:wc-picked@.step-picked^ev="val.step"></mx-step> | ||
| <mx-step id="wcStep" data-m-ex:.@wc-step="'' + val" data-m-ex:wc-picked@.step-picked^ev="val.step" data-m-ex:wc-step@wc-picked="'' + val"></mx-step> |
There was a problem hiding this comment.
why do we have this ex twice?
- data-m-ex:.@wc-step
- data-m-ex:wc-step@wc-picked
why do we need "'' + val" in both cases, isn't the val should be used by default?
There was a problem hiding this comment.
@copilot
why do we have this ex twice?
data-m-ex:.@wc-step
data-m-ex:wc-step@wc-picked
why do we need "'' + val" in both cases, isn't the val should be used by default?
There was a problem hiding this comment.
They were doing two different jobs, and the string coercion was unnecessary.
data-m-ex:.@wc-stepkeeps the WC defaultvalueprop in sync when thewc-stepsignal changes (the section 6.a demo of signal → WC default prop).data-m-ex:wc-step@wc-pickedwas only a feedback hop so the custom event could also updatewc-step. That is now one multi-target write from the event:data-m-ex:wc-picked:wc-step@.step-picked^ev="val.step".
'' + val is not needed either — omitting the expression already defaults to val (data-m-ex:.@count ≡ ="val"), and number → value / textContent coercion is fine here.
Simplified markup in d9faa34:
<mx-step id="wcStep" data-m-ex:.@wc-step data-m-ex:wc-picked:wc-step@.step-picked^ev="val.step"></mx-step>Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
The
mx-stepWeb Component dispatchedstep-pickedwiththis._value + 1on every click but never mutatedthis._value, so every click emittedstep: 1and the counter appeared frozen.Changes
mx-steponclick — incrementthis._valuein-place and update the shadow<output>before dispatching, so consecutive clicks accumulate:mx-stepelement binding — addeddata-m-ex:wc-step@wc-picked="'' + val"to close the feedback loop: when thewc-pickedstore updates from the custom event,wc-stepis also updated, keeping the "WC default value prop"<span>in sync.