Skip to content

Commit 412c40a

Browse files
committed
feat: allow to explicitly declare attributes as global
1 parent dbc885e commit 412c40a

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
@@ -356,6 +356,21 @@ describe('moddle', function() {
356356
expect(element.get('props:count')).to.eql(10);
357357
});
358358

359+
360+
it('should access global name', function() {
361+
362+
// when
363+
const element = moddle.create('props:ComplexCount', {
364+
':xmlns': 'http://foo'
365+
});
366+
367+
// then
368+
expect(element.get(':xmlns')).to.eql('http://foo');
369+
370+
// available as extension attribute
371+
expect(element.$attrs).to.have.property('xmlns');
372+
});
373+
359374
});
360375

361376

@@ -411,6 +426,21 @@ describe('moddle', function() {
411426
});
412427

413428

429+
it('should access global name', function() {
430+
431+
// when
432+
const element = moddle.create('props:ComplexCount', {
433+
':xmlns': 'http://foo'
434+
});
435+
436+
// then
437+
expect(element.get(':xmlns')).to.eql('http://foo');
438+
439+
// available as extension attribute
440+
expect(element.$attrs).to.have.property('xmlns');
441+
});
442+
443+
414444
it('fail accessing unknown property', function() {
415445

416446
// when

0 commit comments

Comments
 (0)