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

Clean up some Glimmer deprecations #33

Merged

Conversation

jamesarosen
Copy link
Contributor

  1. test against Ember 1.13.2
  2. change {{#each foo in foos}} to {{#each foos as |foo|}}
  3. introduce getComponentById helper that uses app.__container__.lookup('-view-registry:main') since Ember no longer exposes Ember.View.views
  4. don't call set in didInsertElemenent because that can cause performance problems in Glimmer; instead, defer the set to the afterRender queue
  5. eliminate use of Ember.ObjectController in tests
  6. use the change handler that Ember.Components come with instead of adding a handler in didInsertElement via this.$.on('change')
  7. remove observer on content.@each that was writing changes back upstream and sending actions. In Glimmer, the component will get rerendered automatically from upstream changes; it only needs to notify when the source of the change is a DOM event within its element
  8. when no item is selected, set value and selection to null, not undefined; the latter has problems with properties that use alias
  9. upgrade ember-cli-app-version to remove some warnings
  10. warn if the user passes form since Glimmer doesn't support that at the moment. See Using attributeBindings for component in 1.11+ doesn't bind the form attr emberjs/ember.js#11221

expect(this.$('option:eq(2)')).to.be.selected;
expect(this.$('option:eq(0)').is('[selected]')).to.be.falsy;
expect(this.$('option:eq(1)').is('[selected]')).to.be.truthy;
expect(this.$('option:eq(2)').is('[selected]')).to.be.truthy;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suprised that this doesn't work reliably when it always seems to have in the past. This is pretty vanilla chai-jquery, and I'm curious what changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure. My guess was that Glimmer wasn't able to set the actual DOM property, but only the attribute.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was wrong. The problem is that _updateValueMultiple is getting triggered on insert, which causes selection to get written to, overriding the passed-in value.

@cowboyd
Copy link
Collaborator

cowboyd commented Jun 24, 2015

Thanks for undertaking this work @jamesarosen!

The only question I have is how this will affect users of Ember < 1.13. It looks like most of the new apis are only used inside the tests, and the only usage of a new api in application code that I can see is change to hasBlock inside the x-select template.

I'm not opposed to increasing the minimum Ember version, just want to be deliberate about understanding what it is.

@jamesarosen
Copy link
Contributor Author

When I did similar work for ember-i18n, I did increase the minimum version and bumped the major version of the library.

@jeremywrowe
Copy link
Contributor

Might be worth checking out: https://github.com/rwjblue/ember-cli-version-checker

James A. Rosen added 9 commits June 27, 2015 16:35
Prefer `{{#each foos as |bar|}}` to `{{#each foo in foos}}`. This
eliminates some deprecation warnings following the ember upgrade.
In Ember 1.13, `Ember.View.views` no longer exists. It has been replaced by
the (equally private) `container.lookup('-view-registry:main')`. This extracts
that lookup to a test helper so the reliance on a private API is at least
isolated.
In Glimmer, that can cause performance problems. Instead, we use `didInsertElement`
to schedule an `afterRender` callback that sets the `x-option`'s `select`.
`Ember.ObjectController` has been deprecated. Using it causes a warning about
proxying properties.
Ember views automatically call `.change()` on DOM change events, so
we can use that hook instead of adding a change handler in `didInsertElement`
and tearing it down in `willDestroyElement`.

This is now the only place we need to call `_updateValueSingle` or
`_updateValueMultiple`. We don't need to do that when the content changes
from upstream since (in Glimmer) the component will render the difference
automatically. Calling those in an observer on `content.@each` was causing
upstream writes to happen unnecessarily.
`Ember.computed.alias` treats `undefined` specially, causing some writes
to fail.
@jamesarosen
Copy link
Contributor Author

This JSBin shows that we can support form binding in theory. We can wait for emberjs/ember.js#11221 to land and then make it into an Ember release. Or we could work around it here:

_updateForm: Ember.on('didRender', function() {
  if (form) { this.$().attr('form', this.get('form')); }
});

James A. Rosen added 2 commits June 27, 2015 22:16
Glimmer currently doesn't support binding the `form` attribute because
of how it detects settable attributes vs properties.

See emberjs/ember.js#11221
@jamesarosen jamesarosen force-pushed the glimmer-deprecations branch from 4712739 to b693a37 Compare June 28, 2015 05:18
@jamesarosen
Copy link
Contributor Author

I've updated this PR to bring support for form back via a custom workaround in x-select.

@Robdel12
Copy link
Collaborator

That's awesome! I'm good with this as long as we figure out backward compatibility.

Any thoughts @cowboyd?

@jamesarosen
Copy link
Contributor Author

pagination-pager has a compatibility table:

Plugin Version Ember Version
0.x Globals Version, < 1.13
1.x < 1.13
2.x 1.13

@Robdel12 Robdel12 merged commit b693a37 into adopted-ember-addons:master Jul 2, 2015
@Robdel12
Copy link
Collaborator

Robdel12 commented Jul 2, 2015

Hey @jamesarosen, thank you so much for this PR!! It's really appreicated

@jamesarosen jamesarosen deleted the glimmer-deprecations branch July 2, 2015 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants