Skip to content

Commit c0f7e98

Browse files
hemkaranyowainwright
authored andcommitted
fix(): Fixing context passing while calling child model function (dollarshaveclub#182)
* fix(): Fixing context passing while calling child model function dollarshaveclub#181 * Fixing circle ci build to build the dist files
1 parent d2a5572 commit c0f7e98

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
- restore_cache: *restore_cache
2626
- run: npm install
2727
- run: npm run eslint:ci
28+
- run: npm run build
2829
- run: npm test
2930
- run: npx codecov
3031
- save_cache: *save_cache

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ coverage/
99
coverage.lcov
1010
coverage_*/
1111
yarn.lock
12+
.idea/

src/postmate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export class ChildAPI {
202202

203203
if (e.data.postmate === 'call') {
204204
if (property in this.model && typeof this.model[property] === 'function') {
205-
this.model[property].call(this, data)
205+
this.model[property](data)
206206
}
207207
return
208208
}

test/acceptance/fixtures/child.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
4545
a: a,
4646
b: b,
4747
setRandomId: setRandomId,
48-
getRandomId: getRandomId
48+
getRandomId: getRandomId,
49+
setFoo: function (foo) {
50+
this.foo = foo;
51+
}
4952
})
5053
.then(function (parent) { parentAPI = parent; });
5154
</script>

test/acceptance/test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,21 @@ describe('postmate', function () {
6969
})
7070
})
7171

72+
it('should call a function in the child model with the child model context', function (done) {
73+
new Postmate({
74+
container: document.getElementById('frame'),
75+
url: 'http://localhost:9000/child.html',
76+
}).then(function (child) {
77+
child.call('setFoo', 'bar')
78+
child.get('foo').then(function (foo) {
79+
expect(foo).to.equal('bar')
80+
child.destroy()
81+
done()
82+
})
83+
.catch(function (err) { done(err) })
84+
})
85+
})
86+
7287
it('should fetch values from the child model from defaults set by the parent', function (done) {
7388
var uid = new Date().getTime()
7489

0 commit comments

Comments
 (0)