-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- remove unused dependencies - replace usage of unnecessary packages
- Loading branch information
1 parent
38b8c0e
commit fc70cfb
Showing
11 changed files
with
1,345 additions
and
10,641 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { SafeEventEmitter } from "@toruslabs/openlogin-jrpc"; | ||
|
||
export class ObservableStore<T> extends SafeEventEmitter { | ||
private _state: T; | ||
|
||
constructor(initState: T) { | ||
super(); | ||
if (initState === undefined) { | ||
this._state = {} as unknown as T; | ||
} else { | ||
this._state = initState; | ||
} | ||
} | ||
|
||
getState(): T { | ||
return this._getState(); | ||
} | ||
|
||
putState(newState: T): void { | ||
this._putState(newState); | ||
this.emit("update", newState); | ||
} | ||
|
||
updateState(partialState: Partial<T>): void { | ||
// if non-null object, merge | ||
if (partialState && typeof partialState === "object") { | ||
const state = this.getState(); | ||
this.putState({ ...state, ...partialState }); | ||
// if not object, use new value | ||
} else { | ||
this.putState(partialState as T); | ||
} | ||
} | ||
|
||
subscribe(handler: (state: T) => void): void { | ||
this.on("update", handler); | ||
} | ||
|
||
unsubscribe(handler: (state: T) => void): void { | ||
this.removeListener("update", handler); | ||
} | ||
|
||
protected _getState(): T { | ||
return this._state; | ||
} | ||
|
||
protected _putState(newState: T): void { | ||
this._state = newState; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { _IWritable, Duplex as DuplexStream } from "readable-stream"; | ||
|
||
import { ObservableStore } from "./ObservableStore"; | ||
|
||
class ObservableStoreStream<T> extends DuplexStream { | ||
handler: (state: T) => void; | ||
|
||
obsStore: ObservableStore<T>; | ||
|
||
constructor(obsStore: ObservableStore<T>) { | ||
super({ | ||
// pass values, not serializations | ||
objectMode: true, | ||
}); | ||
// dont buffer outgoing updates | ||
this.resume(); | ||
// save handler so we can unsubscribe later | ||
this.handler = (state: T) => this.push(state); | ||
// subscribe to obsStore changes | ||
this.obsStore = obsStore; | ||
this.obsStore.subscribe(this.handler); | ||
} | ||
|
||
// emit current state on new destination | ||
pipe<U extends _IWritable>(dest: U, options?: { end?: boolean }): U { | ||
const result = super.pipe(dest, options); | ||
dest.write(this.obsStore.getState() as any); | ||
return result; | ||
} | ||
|
||
// write from incoming stream to state | ||
_write(chunk: any, _encoding: string, callback: (error?: Error | null) => void): void { | ||
this.obsStore.putState(chunk); | ||
callback(); | ||
} | ||
|
||
// noop - outgoing stream is asking us if we have data we arent giving it | ||
_read(_size: number): void { | ||
return undefined; | ||
} | ||
|
||
// unsubscribe from event emitter | ||
_destroy(err: Error | null, callback: (error: Error | null) => void): void { | ||
this.obsStore.unsubscribe(this.handler); | ||
super._destroy(err, callback); | ||
} | ||
} | ||
|
||
export function storeAsStream<T>(obsStore: ObservableStore<T>): ObservableStoreStream<T> { | ||
return new ObservableStoreStream(obsStore); | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<head> | ||
<title>Torus Embed Test</title> | ||
</head> | ||
<body> | ||
<script src="../dist/torus.umd.min.js"></script> | ||
<script> | ||
console.log(Torus); | ||
</script> | ||
</body> |
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,3 +1,3 @@ | ||
module.exports = { | ||
analyzerMode: "disabled", | ||
analyzerMode: "static", | ||
}; |
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