question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deeply nested properties do not trigger template getter on rollback

See original GitHub issue

Version

2.0.0

Test Case

https://github.com/neighborly/changeset-test

Steps to reproduce

We are building a generalized form component based on ember-changeset that yields a set of input fields that are automatically bound to the changeset by a fieldName property. The value of these inputs is bound by a template getter to the this.fieldName property within the changeset, and onInput is bound to action (changeset-set this.changeSet this.fieldName) value="target.value". The changeset picks-up on the changes to the input; however, when the form is reset, the changes clear from the changeset, but the inputs do not reset their values.

It seems like the {{get}} helper only binds to the first token in a complex property key. This does not happen on properties that are at the top-level of the changeset model. For example, this will occur on a name.first property, but not on a email property.

Here is a demo app that illustrates the idea: https://github.com/neighborly/changeset-test

In this demo app change both of the values in the inputs, and click the reset button. You will only see the email field reset.

Expected Behavior

Expected behavior is that any property would update when reset.

Actual Behavior

Actual behavior is that the deeply nested properties do not update when reset.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
rreckonerrcommented, Oct 4, 2019

That’s the solution

  init(...args) {
    this._super(...args)

    defineProperty(
      this,
      'value',
      computed(`model.${this.attribute}`, `model.{_content,_changes}` {
        get() {
          const model = get(this, 'model')
          return isChangeset(model) ? model.get(this.attribute) : get(this, `model.${this.attribute}`)
        },
        set(_, value) {
          const model = get(this, 'model')
          isChangeset(model) ? model.set(this.attribute, value) : set(this, `model.${this.attribute}`, value)
          return value
        }
      })
    )
  }
1reaction
hoIIercommented, Jun 25, 2019

hey, using latest 2.1.2 with {{changeset-get}} and having same issue where a nested key isn’t being updated after it’s changed.

e.g. new Changeset({ params: { query: '' }}), <input value={{changeset-get changeset "params.query"}}> If I mutate the value of changeset.get(‘params.query’), the input in the template will not update. Any ideas?

also here is a way to spy on a dynamic dependent key in:

    init() {
      super.init(...arguments);

      // define dynamic computed selected at runtime.
      defineProperty(this, 'selected', computed(`changeset.${this.name}`, {
        get() {
          if (this.changeset) {
            return this.changeset.get(this.name);
          }
          return null;
        },
      }));
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Trigger splits not working with nested properties | Community
Hi, I have a pretty complicated event that I want to use in my flow. As you can see below, the event is...
Read more >
How to properly interpolate a nested property getter in angualr ...
But I know for sure that myProps is not null because when I'm console-logging the myObject , I can click on the Invoke...
Read more >
Configuration (FreeMarker 2.3.31 API)
A Configuration object is thread-safe only after you have stopped modifying ... #include and #nested doesn't change the parent Template (see Configurable.
Read more >
Spring Boot Reference Documentation
Spring Boot provides an alternative method of working with properties that lets strongly typed beans govern and validate the configuration of your application....
Read more >
SailPoint IdentityIQ Administration Guide
Importing Email Templates into IdentityIQ . ... Do not remove assigned entitlements from an identity when a detected role with which they are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found