Skip to content
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

[Glimmer2] Add mut helper and update readonly helper #13541

Closed
wants to merge 14 commits into from

Conversation

Joelkang
Copy link
Contributor

@Joelkang Joelkang commented May 21, 2016

Implemented based on comments in #13502

  • readonly helper tests forthcoming
  • Support for invoking closure actions with the mut helper
  • {{mut}} of {{readonly}} support
  • {{action attrs.somethingUndefined}} returns PropertyReference as opposed to UNDEFINED_REFERENCE, causing a call-time error rather than a create time error

@Joelkang Joelkang changed the title [Glimmer2] Add mut helper and update readonly helper [WIP][Glimmer2] Add mut helper and update readonly helper May 21, 2016
@@ -76,7 +76,7 @@ moduleFor('@htmlbars Mutable bindings integration tests', class extends Renderin
}

// See https://github.com/emberjs/ember.js/commit/807a0cd for an explanation of this test
['@test using a string value through middle tier does not trigger assertion'](assert) {
['@htmlbars using a string value through middle tier does not trigger assertion'](assert) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because the mut wrapping isn't happening?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right; updated

@homu
Copy link
Contributor

homu commented May 22, 2016

☔ The latest upstream changes (presumably 3a61d98) made this pull request unmergeable. Please resolve the merge conflicts.

@Joelkang Joelkang force-pushed the mut branch 2 times, most recently from 1d15660 to 863bf3a Compare May 25, 2016 00:11
this.assert.equal(get(this.context, 'val'), 12, 'upstream attribute is not updated');
}

['@htmlbars {{mut}} of a {{readonly}} mutates only the middle and bottom tiers']() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krisselden @chancancode so this is still failing in glimmer.

To make it backwards compatible for curly components, what ember-htmlbars seems to be doing is disconnecting the readonly if it is updated from a child, such that get(child, 'parentAttr') is no longer the same as child.attr.parentAttr. But when a change comes from the upstream property, the value correctly updates.

I've tried a variety of ways of disconnecting the value from the reference and reconnecting it, but nothing I've tried really works .It also seems like there could be multiple places this logic can go into (should it be in process-args or mut?) Any direction here would be helpful.

@Joelkang Joelkang force-pushed the mut branch 2 times, most recently from faf561e to 182adfd Compare May 25, 2016 00:20
}

update(val) {
this._ref[UPDATE](val);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the value need to be reflected on both sides?

Copy link
Contributor Author

@Joelkang Joelkang May 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I added tests to verify the value of component.attrs.myAttr.value and component.get('myAttr')and they all seem to be passing after the update() without any code changes. Is that what you meant?

@Joelkang Joelkang force-pushed the mut branch 2 times, most recently from c62db4f to 9e16add Compare May 31, 2016 18:15
@Joelkang Joelkang changed the title [WIP][Glimmer2] Add mut helper and update readonly helper [Glimmer2] Add mut helper and update readonly helper May 31, 2016
@@ -2,7 +2,8 @@ import run from 'ember-metal/run_loop';
import { computed } from 'ember-metal/computed';
import isEnabled from 'ember-metal/features';
import { subscribe, unsubscribe } from 'ember-metal/instrumentation';
import { INVOKE } from 'ember-htmlbars/keywords/closure-action';
import { INVOKE as HTMLBARS_INVOKE } from 'ember-htmlbars/keywords/closure-action';
import { INVOKE as GLIMMER_INVOKE } from 'ember-glimmer/utils/references';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to put this forking into one of the helper files so that the test can just import { INVOKE } from '../../utils/helpers'; and it would get either the HTMLBars or Glimmer symbol.

@homu
Copy link
Contributor

homu commented Jun 5, 2016

☔ The latest upstream changes (presumably 0f2d9e6) made this pull request unmergeable. Please resolve the merge conflicts.

let name = this._debugContainerKey.split(':')[1];
let value = get(this, key);
throw new Error(strip`
let name = this._debugContainerKey.split(':')[1];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only used for the assertion, but as written it will not get stripped. Can you refactor to avoid splitting in prod builds where the assertion is not needed? Something like:

let value = get(this, key);
runInDebug(function() {
  let name = this._debugContainerKey.split(':')[1];
  assert(strip`
    Cannot set the \`${key}\` property (on component ${name}) to
    \`${value}\`. The \`${key}\` property came from an immutable
    binding in the template, such as {{${name} ${key}="string"}}
    or {{${name} ${key}=(if theTruth "truth" "false")}}.
  `, reference[UPDATE]);
});

reference[UPDATE](value);

@rwjblue
Copy link
Member

rwjblue commented Jun 5, 2016

This is looking really good. I am no expert in the ember-glimmer techniques (I'll leave that to the rest of the team) but I am curious what you see as the roadmap for this PR. What is still outstanding, what is blocking, etc...

One thing I was noticing/thinking about was the auto-mut AST transform, should that be reenabled in this PR?

@Joelkang
Copy link
Contributor Author

Joelkang commented Jun 8, 2016

Rebased and addressed your concerns, @rwjblue . As far as a I can tell there's nothing really blocking this PR, once these issues are resolved

} else if (actionType !== 'function') {
throw new EmberError(`An action could not be made for \`${rawAction}\` in ${target}. Please confirm that you are using either a quoted action name (i.e. \`(action '${rawAction}')\`) or a function available in ${target}.`);
// FIXME: Is there a better way of doing this?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to a TODO:? I discussed with @chancancode and this seems okish for now, and we can circle back to it later...

@rwjblue
Copy link
Member

rwjblue commented Jun 11, 2016

I was chatting with @chancancode about this abit today, he is going to try to give it more review sometime next week...

@homu
Copy link
Contributor

homu commented Jun 11, 2016

☔ The latest upstream changes (presumably #13492) made this pull request unmergeable. Please resolve the merge conflicts.

@homu
Copy link
Contributor

homu commented Jun 15, 2016

☔ The latest upstream changes (presumably #13680) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants