-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Made template context reactive and emit events (closes #999)
- Loading branch information
Showing
2 changed files
with
16 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
// This is a singleton used to inject data in string template evaluation contexts (lodash) | ||
export const TemplateContext = { | ||
initialize () { | ||
if (this.ctx) return | ||
this.ctx = {} | ||
}, | ||
import { useStore } from './composables/store.js' | ||
import { Events } from './events.js' | ||
|
||
get () { | ||
return this.ctx | ||
}, | ||
const { store, set, get, unset, has } = useStore('template-context') | ||
|
||
merge (ctx) { | ||
this.ctx = Object.assign({}, this.ctx, ctx) | ||
// This is a singleton used to inject data in string template evaluation contexts (lodash) | ||
export const TemplateContext = Object.assign(store, { | ||
get, | ||
has, | ||
unset, | ||
// Override write methods to send events | ||
set (path, value) { | ||
const previousValue = get(path) | ||
set(path, value) | ||
Events.emit('template-context-changed', path, value, previousValue) | ||
} | ||
} | ||
|
||
TemplateContext.initialize() | ||
}) |