Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
stephband committed Oct 20, 2024
2 parents be0fb73 + 690e082 commit 3ffc496
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions modules/element/create-attribute.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

import clamp from 'fn/clamp.js';
import id from 'fn/id.js';
import overload from 'fn/overload.js';
import toType from 'fn/to-type.js';
Expand All @@ -15,11 +16,11 @@ function getSignal(element, name, initial) {
);
}

export function createAttribute(name, parse = id) {
export function createAttribute(name, initial, parse = id) {
return {
attribute: function(value) {
const signal = getSignal(this, name);
signal.value = parse(value);
signal.value = value === null ? initial : parse(value) ;
}
};
}
Expand All @@ -43,7 +44,7 @@ export function createProperty(name, initial, parse = id) {
export function createAttributeProperty(name, initial, parse = id) {
return assign(createProperty(name, initial, parse), {
attribute: function(value) {
this[name] = value === null ? undefined : value ;
this[name] = value === null ? undefined : value.trim() ;
}
});
}
Expand All @@ -68,8 +69,8 @@ export function createStringAttribute(name, parse = id) {
});
}

export function createNumberAttribute(name, min, max, parse = id) {
return createAttributeProperty(name, 0, (value) => {
export function createNumberAttribute(name, initial, min, max, parse = id) {
return createAttributeProperty(name, initial, (value) => {
const number = parse(value);

if (Number.isNaN(number)) {
Expand Down

0 comments on commit 3ffc496

Please sign in to comment.