Skip to content

Commit

Permalink
feat: add model.ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-horse committed Jul 10, 2019
1 parent 78e5193 commit f760569
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
coverage
fixtures
5 changes: 4 additions & 1 deletion lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ module.exports = app => {
get() {
// context.model is different with app.model
// so we can change the properties of ctx.model.xxx
if (!this[DELEGATE]) this[DELEGATE] = Object.create(model[delegate[len - 1]]);
if (!this[DELEGATE]) {
this[DELEGATE] = Object.create(model[delegate[len - 1]]);
this[DELEGATE].ctx = this;
}
return this[DELEGATE];
},
configurable: true,
Expand Down
1 change: 1 addition & 0 deletions test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('test/plugin.test.js', () => {
it('ctx model property getter', () => {
const ctx = app.mockContext();
assert.ok(ctx.model);
assert.ok(ctx.model.ctx === ctx);
assert.ok(ctx.model.User);
assert.ok(ctx.model.Monkey);
assert.ok(ctx.model.Person);
Expand Down

0 comments on commit f760569

Please sign in to comment.