-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📦 NEW: Support localStorage getter (#21)
- Loading branch information
Showing
7 changed files
with
79 additions
and
40 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,33 +1,29 @@ | ||
// Type definitions for sdk-base 3.4 | ||
// Project: https://github.com/node-modules/sdk-base | ||
// Definitions by: Sang Lv <https://github.com/sang4lv> | ||
// TypeScript Version: 2.9.2 | ||
|
||
/* =================== USAGE =================== | ||
import Base from "sdk-base"; | ||
class newSDK extends Base {} | ||
=============================================== */ | ||
|
||
/// <reference types="node" /> | ||
import Base from "sdk-base"; | ||
class newSDK extends Base {} | ||
class newSDK extends Base<FooContext> {} | ||
=============================================== */ | ||
|
||
import { EventEmitter } from 'events'; | ||
import { AsyncLocalStorage } from 'async_hooks'; | ||
|
||
interface BaseOptions { | ||
initMethod?: string; | ||
[key: string]: any; | ||
export interface BaseOptions { | ||
initMethod?: string; | ||
localStorage?: any; | ||
[key: string]: any; | ||
} | ||
|
||
export default class Base extends EventEmitter { | ||
constructor(option?: BaseOptions); | ||
export default class Base<TContext = any> extends EventEmitter { | ||
constructor(option?: BaseOptions); | ||
|
||
isReady: boolean; | ||
options: BaseOptions; | ||
await(...args: any[]): Promise<any>; | ||
awaitFirst(...args: any[]): Promise<any>; | ||
ready(): Promise<any>; | ||
ready(err: Error): void; | ||
ready(ready: boolean): void; | ||
ready(readyCallback: Function): void; | ||
readyOrTimeout(milliseconds: number): Promise<void>; | ||
isReady: boolean; | ||
options: BaseOptions; | ||
localStorage?: AsyncLocalStorage<TContext>; | ||
await(...args: any[]): Promise<any>; | ||
awaitFirst(...args: any[]): Promise<any>; | ||
ready(): Promise<any>; | ||
ready(err: Error): void; | ||
ready(ready: boolean): void; | ||
ready(readyCallback: Function): void; | ||
readyOrTimeout(milliseconds: number): Promise<void>; | ||
} |
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,11 +1,31 @@ | ||
import { expectType } from 'tsd'; | ||
import { AsyncLocalStorage } from 'async_hooks'; | ||
import Base from '.'; | ||
|
||
class Client extends Base { | ||
|
||
class MockContenxt {} | ||
|
||
class Client extends Base<MockContenxt> { | ||
constructor() { | ||
super({ | ||
initMethod: 'init', | ||
localStorage: new AsyncLocalStorage<MockContenxt>, | ||
}); | ||
} | ||
} | ||
|
||
const client = new Client(); | ||
|
||
expectType<Promise<void>>(client.readyOrTimeout(1000)); | ||
expectType<Promise<any>>(client.ready()); | ||
expectType<MockContenxt | undefined>(client.localStorage?.getStore()); | ||
|
||
class ClientDefaultContext extends Base { | ||
constructor() { | ||
super({ | ||
initMethod: 'init', | ||
}); | ||
} | ||
} | ||
|
||
const client2 = new ClientDefaultContext(); | ||
expectType<any | undefined>(client2.localStorage?.getStore()); |
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