-
Notifications
You must be signed in to change notification settings - Fork 178
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
Input value
set as attribute
#67
Comments
React has a lot of code to support these |
@jridgewell sounds good. Then I can use it too for jsx html/dom renderers, so one JSX input could be transformed to equivalent (in terms of end tree) HTML, DOM or Incremental DOM output. |
We probably can has separate npm package so all can depend on it and this way almost all tests will be one place, + same update for everyone. |
Maybe we could test for property existance on the element and read/write from/to this, otherwise use get/setAttribute...? Related to #57 |
I am curious why setting for example |
See #45 for a bit more context. |
For Setting arbitrary things as properties would definitely be faster, but there already exists a lot of markup (and logic relying on that markup) that uses non |
@sparhami configuration options sounds good, exactly that I thought. Also, about <div class="list-item"
data-bind="item"
itemData={ item.data }
>
...
</div> In this case it would be good to translate |
We could deliver a dedicated props object together with staticattrs / attrs and allow for properties to be set only through this. All other keyvalues would then be set as attributes. This would offload responsibility to the developer or transformer logic, but would also simplify the whole process of knowing what's a property and what is an attribute. |
This is more thought out version of google#72, providing both fine grained attribute setting as well as generic overrides. I prefer this style because it does not expose private workings publicly (`updateAttribute` depends on `attributes.applyStyle`, etc). I'm still publicly exposing our default mutators so they may be reused in any custom mutator, but mutating the `defaults` object will not cause any unintended side-effects (references are used, not object property lookups). This solves google#67 by providing a list of known properties that cannot be set as attributes, even if they're a string. The main criticisms of google#72 were, 1) filesize, 2) custom attributes. This aims to solve both. 1. No more giant list of attributes to apply as attributes. Defining the few property exceptions is much smaller. - 120 bytes after gzipping. If you verify, note that the current mast does not include the `@license` comment in the build file while this build will. 2. We continue to use `typeof` to guess, and a special `__all__` mutator can be defined to provide generic overriding.
This is more thought out version of google#72, providing both fine grained attribute setting as well as generic overrides. I prefer this style because it does not expose private workings publicly (`updateAttribute` depends on `attributes.applyStyle`, etc). I'm still publicly exposing our default mutators so they may be reused in any custom mutator, but mutating the `defaults` object will not cause any unintended side-effects (references are used, not object property lookups). This solves google#67 by providing a list of known properties that cannot be set as attributes, even if they're a string. The main criticisms of google#72 were, 1) filesize, 2) custom attributes. This aims to solve both. 1. No more giant list of attributes to apply as attributes. Defining the few property exceptions is much smaller. - 120 bytes after gzipping. If you verify, note that the current mast does not include the `@license` comment in the build file while this build will. 2. We continue to use `typeof` to guess, and a special `__all__` mutator can be defined to provide generic overriding.
I've actually ran into the same problem as @peterwmwong initially mentioned, and I've been thinking about it. My initial approach was just to change the After a few iterations, I've came up with this solution, which I think it's easier to maintain than having a complete map of attributes and their way of being updated. Basically we first update the attribute, and after, if the corresponding property hasn't been updated, we change it as well. However, I'm pretty sure it has some caveats, and might not fit all cases, but just to give some other options on it. 😃 |
So any updates on this? @jridgewell @sparhami |
Doesn't your solution also cause issues? With the current codebase, you can set iDOM.mutators.attributes[iDOM.symbols.all] = function(el, name, value) {
var type = typeof value;
var propertyName;
if (PROPERTY_MAP.hasOwnProperty(name)) {
propertyName = PROPERTY_MAP[name];
} else {
propertyName = name;
}
if (value === undefined) {
el.removeAttribute(name);
} else if ((typeof value !== 'function') && (typeof value !== 'object')) {
el.setAttribute(name, value);
}
// If, after changing the attribute, the corresponding property is not updated,
// also update it.
if (el[propertyName] !== value) {
el[propertyName] = value;
}
}; |
Also, |
Sounds good to me. |
Referenced code (this one) does not cause issues, because, when writing, the On the other side, if you change the value externally, and then you patch, the Although the code supports mutators now, I would say that the fix should be included in the core of the library, rather than as an additional "plugin"; mainly because I think this is the default behavior you expect. |
Consider the following failing test case...
Input text is still "NOT RIGHT" and not "Hello World"
Currently, IncrementalDOM decides how to assign an attribute based on the value's type.
Function and Objects are assigned as properties (ex.
node.onclick = function(){}
). Everythingelse is assigned with
setAttribute()
/removeAttribute
. DocsUnfortunately, setting an
<input>
'svalue
(orchecked
) must be set as a property after the usertypes in the input.
Currently, I'm working around the issue by wrapping the attribute's value with
new String()
...... this works as
typeof (new String('Hello World')) === 'object'
.Not sure if a change is needed or just requires docs to note a workaround.
Here's the requirebin's for the above testcase and workaround:
http://requirebin.com/?gist=100e687ddffd8de6e59c
http://requirebin.com/?gist=7c30ebcf7613c5afc947
The text was updated successfully, but these errors were encountered: