Skip to content

Commit

Permalink
fix(core): copy initial values to the prop before creating setter/get…
Browse files Browse the repository at this point in the history
…ters
  • Loading branch information
tusharmath committed Sep 14, 2016
1 parent 9a589bc commit 23015bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/createWCProto.js
Expand Up @@ -68,6 +68,7 @@ export default (virtualDOMPatcher, component) => {
this.__render = this.__render.bind(this)

props.forEach(p => {
this.__props[p] = this[p]
Object.defineProperty(this, p, {
get: () => this.__props[p],
set: (params) => {
Expand Down
14 changes: 14 additions & 0 deletions test/test.createWCProto.js
Expand Up @@ -235,3 +235,17 @@ test('__reducer', t => {
])
t.true(wc.dispatchEvent.calledWith(mockEV))
})
test('createdCallback():copy-initial-values', t => {
const mockPatcher = createMockPatcher()
const attachShadow = () => '@ROOT'
const component = createMockComponent()
const wc = rwc.createWCProto(mockPatcher.patcher, component)
wc.attachShadow = attachShadow
wc['A'] = 'aaa-initial-value'
wc['B'] = 'bbb-initial-value'
wc['C'] = 'ccc-initial-value'
wc.createdCallback()
t.is(wc['A'], 'aaa-initial-value')
t.is(wc['B'], 'bbb-initial-value')
t.is(wc['C'], 'ccc-initial-value')
})

0 comments on commit 23015bb

Please sign in to comment.