Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/ember-glimmer/lib/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ const Component = CoreView.extend(
}
},

readDOMAttr(name) {
// TODO this is probably not correct
return this.element.getAttribute(name);
},

[TO_ROOT_REFERENCE]() {
let ref = this[ROOT_REF];

Expand Down
38 changes: 38 additions & 0 deletions packages/ember-htmlbars/lib/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,44 @@ const Component = View.extend(TargetActionSupport, {
return parentView ? get(parentView, 'controller') : null;
}),

/**
Normally, Ember's component model is "write-only". The component takes a
bunch of attributes that it got passed in, and uses them to render its
template.

One nice thing about this model is that if you try to set a value to the
same thing as last time, Ember (through HTMLBars) will avoid doing any
work on the DOM.

This is not just a performance optimization. If an attribute has not
changed, it is important not to clobber the element's "hidden state".
For example, if you set an input's `value` to the same value as before,
it will clobber selection state and cursor position. In other words,
setting an attribute is not **always** idempotent.

This method provides a way to read an element's attribute and also
update the last value Ember knows about at the same time. This makes
setting an attribute idempotent.

In particular, what this means is that if you get an `<input>` element's
`value` attribute and then re-render the template with the same value,
it will avoid clobbering the cursor and selection position.

Since most attribute sets are idempotent in the browser, you typically
can get away with reading attributes using jQuery, but the most reliable
way to do so is through this method.

@method readDOMAttr
@param {String} name the name of the attribute
@return String
@public
*/
readDOMAttr(name) {
let attr = this._renderNode.childNodes.filter(node => node.attrName === name)[0];
if (!attr) { return null; }
return attr.getContent();
},

/**
Calls an action passed to a component.

Expand Down
38 changes: 0 additions & 38 deletions packages/ember-views/lib/mixins/view_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,44 +454,6 @@ export default Mixin.create({
@private
*/

/**
Normally, Ember's component model is "write-only". The component takes a
bunch of attributes that it got passed in, and uses them to render its
template.

One nice thing about this model is that if you try to set a value to the
same thing as last time, Ember (through HTMLBars) will avoid doing any
work on the DOM.

This is not just a performance optimization. If an attribute has not
changed, it is important not to clobber the element's "hidden state".
For example, if you set an input's `value` to the same value as before,
it will clobber selection state and cursor position. In other words,
setting an attribute is not **always** idempotent.

This method provides a way to read an element's attribute and also
update the last value Ember knows about at the same time. This makes
setting an attribute idempotent.

In particular, what this means is that if you get an `<input>` element's
`value` attribute and then re-render the template with the same value,
it will avoid clobbering the cursor and selection position.

Since most attribute sets are idempotent in the browser, you typically
can get away with reading attributes using jQuery, but the most reliable
way to do so is through this method.

@method readDOMAttr
@param {String} name the name of the attribute
@return String
@public
*/
readDOMAttr(name) {
let attr = this._renderNode.childNodes.filter(node => node.attrName === name)[0];
if (!attr) { return null; }
return attr.getContent();
},

// .......................................................
// CORE DISPLAY METHODS
//
Expand Down