Skip to content

Commit

Permalink
feat: allow to explicitly declare attributes as global
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku committed Dec 17, 2022
1 parent ed6e85a commit 733e24d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Properties.prototype.set = function(target, name, value) {
if (property) {
delete target[propertyName];
} else {
delete target.$attrs[name];
delete target.$attrs[stripGlobal(name)];
}
} else {

Expand All @@ -51,7 +51,7 @@ Properties.prototype.set = function(target, name, value) {
defineProperty(target, property, value);
}
} else {
target.$attrs[name] = value;
target.$attrs[stripGlobal(name)] = value;
}
}
};
Expand All @@ -69,7 +69,7 @@ Properties.prototype.get = function(target, name) {
var property = this.getProperty(target, name);

if (!property) {
return target.$attrs[name];
return target.$attrs[stripGlobal(name)];
}

var propertyName = property.name;
Expand Down Expand Up @@ -168,4 +168,8 @@ function defineProperty(target, property, value) {
value: value,
configurable: true
});
}

function stripGlobal(name) {
return name.replace(/^:/, '');
}
30 changes: 30 additions & 0 deletions test/spec/moddle.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,21 @@ describe('moddle', function() {
});


it('should access global name', function() {

// when
const element = moddle.create('props:ComplexCount', {
':xmlns': 'http://foo'
});

// then
expect(element.get(':xmlns')).to.eql('http://foo');

// available as extension attribute
expect(element.$attrs).to.have.property('xmlns');
});


it('should access refined property, created via base name', function() {

// when
Expand Down Expand Up @@ -435,6 +450,21 @@ describe('moddle', function() {
});


it('should access global name', function() {

// when
const element = moddle.create('props:ComplexCount', {
':xmlns': 'http://foo'
});

// then
expect(element.get(':xmlns')).to.eql('http://foo');

// available as extension attribute
expect(element.$attrs).to.have.property('xmlns');
});


it('fail accessing unknown property', function() {

// when
Expand Down

0 comments on commit 733e24d

Please sign in to comment.