Skip to content

Commit

Permalink
should make shadow properties setter transparent
Browse files Browse the repository at this point in the history
  • Loading branch information
pemrouz committed Apr 27, 2016
1 parent 77c2346 commit 33ab8d6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
9 changes: 7 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ var reflect = function reflect(el) {

var retarget = function retarget(el) {
return (0, _keys2.default)(el).concat(['on', 'once', 'emit', 'classList', 'getAttribute', 'setAttribute']).map(function (d) {
return _is2.default.fn(el[d]) ? el.shadowRoot[d] = el[d].bind(el) : Object.defineProperty(el.shadowRoot, d, { get: function get(z) {
return _is2.default.fn(el[d]) ? el.shadowRoot[d] = el[d].bind(el) : Object.defineProperty(el.shadowRoot, d, {
get: function get(z) {
return el[d];
} });
},
set: function set(z) {
return el[d] = z;
}
});
});
};

Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ const retarget = el => keys(el)
.concat(['on', 'once', 'emit', 'classList', 'getAttribute', 'setAttribute'])
.map(d => is.fn(el[d])
? (el.shadowRoot[d] = el[d].bind(el))
: Object.defineProperty(el.shadowRoot, d, { get: z => el[d] }))
: Object.defineProperty(el.shadowRoot, d, {
get: z => el[d]
, set: z => el[d] = z
})
)

const log = require('utilise/log')('[ri/shadow]')
, err = require('utilise/err')('[ri/shadow]')
Expand Down
16 changes: 15 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('Shadow DOM', function(){
time(100, done)
})

it('should retarget .classed and .attr', function(){
it('should retarget .classed and .attr', function(){
var ripple = shadow(components(fn(data(core()))))

ripple('component-2', noop)
Expand Down Expand Up @@ -138,4 +138,18 @@ describe('Shadow DOM', function(){
expect(root.getAttribute('foo')).to.be.eql('bar')
})

it('should make shadow properties setter transparent', function(){
var ripple = shadow(components(fn(data(core()))))

el2.foo = true
ripple('component-2', noop)
ripple.render(el2)

el2.foo = 10
expect(el2.shadowRoot.foo).to.eql(10)

el2.shadowRoot.foo = 20
expect(el2.foo).to.eql(20)
})

})

0 comments on commit 33ab8d6

Please sign in to comment.