Skip to content

Commit

Permalink
feat: add reset function for observer
Browse files Browse the repository at this point in the history
  • Loading branch information
Nnigmat committed Sep 2, 2021
1 parent 3805120 commit 9dd873b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/core/src/internal/observer.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { compile } from '../index'
import { CompileResult, CompileOptions } from '../compiler'
import { TokenValue } from '../types'
import { RawToken, TokenValue } from '../types'

export type Watcher = (payload: CompileResult) => void
type Compile = typeof compile

export class ThemekitObserver {
private originalTokens: RawToken[]
private options: CompileOptions
private compile: Compile
private watchers: Set<Watcher> = new Set()

constructor(options: CompileOptions, _compile: Compile = compile) {
this.compile = _compile
this.options = options
this.originalTokens = options.tokens
this.run(options)
}

Expand All @@ -29,6 +31,11 @@ export class ThemekitObserver {
this.run(this.options)
}

reset() {
this.options.tokens = this.originalTokens
this.run(this.options)
}

private run(options: CompileOptions) {
setImmediate(() => {
this.emit(this.compile(options))
Expand Down

0 comments on commit 9dd873b

Please sign in to comment.