Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

feat(NodeAttrs): Node attributes don't get initialized by NodeAttrs when #1001

Conversation

mvuksano
Copy link
Contributor

@mvuksano mvuksano commented May 5, 2014

setting up observing.

In case an element does not have an attribute set for a property defined
in NodeAttrs that property is not automatically initialised. Properties
that are initialised have to be set either using "name" or "ng-name"
attribute. For example:

  <div test foo="bar"></div>

will cause ElementBinder to register observer (which will in turn cause
initialisation) on property foo (of the directive) to bar, but if we try
using

  <div test></div>

foo property will not be initialised.

@mvuksano
Copy link
Contributor Author

mvuksano commented May 5, 2014

@mhevery Can you have a look and see if this makes sense? This is related to #981

@mvuksano mvuksano added cla: yes and removed cla: no labels May 5, 2014
@@ -57,7 +57,9 @@ class NodeAttrs {
if (_mustacheAttrs[attrName].isComputed) notifyFn(this[attrName]);
_mustacheAttrs[attrName].notifyFn(true);
} else {
notifyFn(this[attrName]);
if(element.attributes.keys.contains(attrName) || element.attributes.keys.contains('ng-$attrName') || attrName == 'name') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we special casing ng-??? Does not seem right.

Copy link
Contributor

Choose a reason for hiding this comment

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

.keys.contains() -> .containsKey()

@mvuksano mvuksano changed the title [WIP] feat(NodeAttrs): Node attributes don't get initialized by NodeAttrs when feat(NodeAttrs): Node attributes don't get initialized by NodeAttrs when May 12, 2014
@mvuksano
Copy link
Contributor Author

@mhevery What do you think about "boolean attributes" (http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.3.4.2)? Should we initialise them all with true, instead of node.attributes[attrName] (which is I guess null or an empty string)? I think we should do this too.

Actually, thinking more about this... I'm not sure if we can easily differentiate between
<div foo=""></div> - where foo is not a boolean attribute vs <div foo></div> where foo is a boolean attr.

@jbdeboer
Copy link
Contributor

@markovuksanovic This change is ready to be submitted, yes?

@mvuksano
Copy link
Contributor Author

@jbdeboer Yes, given the code is OK :) I just rebased it onto master.

@@ -57,7 +57,10 @@ class NodeAttrs {
if (_mustacheAttrs[attrName].isComputed) notifyFn(this[attrName]);
_mustacheAttrs[attrName].notifyFn(true);
} else {
notifyFn(this[attrName]);
if(element.attributes.keys.contains(attrName)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

containsKey ?

Copy link
Contributor

Choose a reason for hiding this comment

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

space after if

setting up observing.

In case an element does not have a value set for a propertyv, that
property is not automatically initialised. For example:

  <div test foo="bar">

will cause ElementBinder to register observer (which will in turn cause
initialisation) on property foo (of the directive) to bar, but if we try
using

  <div test>

foo property will not be initialised.
@mvuksano
Copy link
Contributor Author

  1. class NgModel extends NgControl
  2. fix attach() - call parent

@jbdeboer
Copy link
Contributor

I'm hesitant about this PR. It is changing the component lifecycle but it unclear what problem it is solving.

I'm not sure that ``null` is the correct choice for an undefined situation. In many cases, components want to set default values for properties and now can't distinguish between a null that was explicitly passed to the component and a null that actually means that the attribute was not defined.

@mvuksano
Copy link
Contributor Author

@jbdeboer It's supposed to solve issue #981.

Regarding null, if the attribute is undefined, maybe we should introduce an Undefined type and call the value with that type. But then we lose some type information...

mvuksano added a commit that referenced this pull request Aug 8, 2014
setting up observing.

In case an element does not have a value set for a propertyv, that
property is not automatically initialised. For example:

  <div test foo="bar">

will cause ElementBinder to register observer (which will in turn cause
initialisation) on property foo (of the directive) to bar, but if we try
using

  <div test>

foo property will not be initialised.

Closes #1001
@@ -57,7 +57,10 @@ class NodeAttrs {
if (_mustacheAttrs[attrName].isComputed) notifyFn(this[attrName]);
_mustacheAttrs[attrName].notifyFn(true);
} else {
notifyFn(this[attrName]);
if (element.attributes.containsKey(attrName)) {
var value = element.attributes[attrName];
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused variable value?

@mhevery
Copy link
Contributor

mhevery commented Aug 26, 2014

Closing, since this PR has perf implication. We really need to solve this in a unified way with bind-.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

5 participants