Skip to content

Commit 733e24d

Browse files
committed
feat: allow to explicitly declare attributes as global
1 parent ed6e85a commit 733e24d

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

lib/properties.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Properties.prototype.set = function(target, name, value) {
3838
if (property) {
3939
delete target[propertyName];
4040
} else {
41-
delete target.$attrs[name];
41+
delete target.$attrs[stripGlobal(name)];
4242
}
4343
} else {
4444

@@ -51,7 +51,7 @@ Properties.prototype.set = function(target, name, value) {
5151
defineProperty(target, property, value);
5252
}
5353
} else {
54-
target.$attrs[name] = value;
54+
target.$attrs[stripGlobal(name)] = value;
5555
}
5656
}
5757
};
@@ -69,7 +69,7 @@ Properties.prototype.get = function(target, name) {
6969
var property = this.getProperty(target, name);
7070

7171
if (!property) {
72-
return target.$attrs[name];
72+
return target.$attrs[stripGlobal(name)];
7373
}
7474

7575
var propertyName = property.name;
@@ -168,4 +168,8 @@ function defineProperty(target, property, value) {
168168
value: value,
169169
configurable: true
170170
});
171+
}
172+
173+
function stripGlobal(name) {
174+
return name.replace(/^:/, '');
171175
}

test/spec/moddle.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,21 @@ describe('moddle', function() {
343343
});
344344

345345

346+
it('should access global name', function() {
347+
348+
// when
349+
const element = moddle.create('props:ComplexCount', {
350+
':xmlns': 'http://foo'
351+
});
352+
353+
// then
354+
expect(element.get(':xmlns')).to.eql('http://foo');
355+
356+
// available as extension attribute
357+
expect(element.$attrs).to.have.property('xmlns');
358+
});
359+
360+
346361
it('should access refined property, created via base name', function() {
347362

348363
// when
@@ -435,6 +450,21 @@ describe('moddle', function() {
435450
});
436451

437452

453+
it('should access global name', function() {
454+
455+
// when
456+
const element = moddle.create('props:ComplexCount', {
457+
':xmlns': 'http://foo'
458+
});
459+
460+
// then
461+
expect(element.get(':xmlns')).to.eql('http://foo');
462+
463+
// available as extension attribute
464+
expect(element.$attrs).to.have.property('xmlns');
465+
});
466+
467+
438468
it('fail accessing unknown property', function() {
439469

440470
// when

0 commit comments

Comments
 (0)