-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syntax color issue #836
Comments
Please share the text of the code along with screenshots |
Hi, sorry for that :-) The code on the screenshot : const _actions = {} as {
[P in keyof Actions] : PropType<Parameters<Actions[P]> , "0"> extends object ?
(payload: PropType<Parameters<Actions[P]> , "0">) => void
:
() => void;
}; And this is the full file : import { Dispatcher } from "../Core/Dispatcher" ;
import { EventBusAutoOff } from "../Utils/Event/EventBus" ;
export type TBaseStore<T> = {
id ?: string ;
nextState : (newState: Partial<T>, mergeToPreviousState?: boolean) => void ;
sendAction : <U>(type: string, payload: U) => void ;
}
export class BaseStore<T> {
protected state !: T ;
id : string = "" ;
mappedActions ?: { [key: string] : string; } ;
protected init : () => void = () => void 0 ;
protected nextState : (newState: Partial<T>, mergeToPreviousState?: boolean) => void = (newState: Partial<T>, mergeToPreviousState?: boolean) => void 0 ;
protected sendAction : <T>(type: string, payload: T) => void = <T>(type: string, payload: T) => void 0 ;
getState() {
return this.state;
}
}
export type TExtentedStore<T> = TBaseStore<T> & {
mappedActions ?: { [key: string] : string; }
}
export type TStoreDefinition<S, T, U> = {
id ?: string ;
localActions ?: boolean ;
actions : T ;
events ?: U ;
mappedActions ?: { [key: string] : string; } ;
init ?: () => void ;
dispatchHandler ?:(this: BaseStore<S>, payload: any, For? : TAwaitFor) => Promise<void> ;
nextState ?: (newState: Partial<S>, mergeToPreviousState?: boolean) => void ;
}
type TRegisterSystem = {
__dispatcher: Dispatcher;
}
export type TActionHandler<T> = (payload: T, For?: TAwaitFor) => TActionReturn ;
export type TActionReturn = Promise<undefined | null | string | string[]> ;
export type TAwaitFor = (...ids: string[]) => Promise<void> ;
export function withEvents<T>(source: T) {
for(const i in source) {
(source as any)[i] = i;
}
return source as T;
}
type PropType<TObj, TProp extends keyof TObj> = TObj[TProp];
type TActionExtention = {[key: string]: (...args: any) => Promise<void | null | string | string[]>};
function _registerStore<State, Actions extends TActionExtention, Events extends { [key: string]: string}> (this: any, def: TStoreDefinition<State, Actions, Events>) {
const _this = <TRegisterSystem>this;
if (!_this.__dispatcher) _this.__dispatcher = new Dispatcher();
const store = new BaseStore<State>();
store.mappedActions = def.mappedActions;
_this.__dispatcher.registerStore(store, def.id);
const _actions = {} as {
[P in keyof Actions] : PropType<Parameters<Actions[P]> , "0"> extends object ?
(payload: PropType<Parameters<Actions[P]> , "0">) => void
:
() => void;
};
for (const key in def.actions) {
(_actions as any)[key] = (_: any) => {
_this.__dispatcher.dispatch({type: def.localActions ? `${def.id}-${key}` : key, ..._});
};
(store as any)[def.localActions ? `${def.id}-${key}` : key] = def.actions[key];
}
if (def.dispatchHandler) {
(store as any)["dispatchHandler"] = def.dispatchHandler;
}
const _subscribeTo = {} as {
[P in keyof Events]: (handler: (newState: State) => void) => EventBusAutoOff;
} & {
All: (handler: (newState: State) => void) => EventBusAutoOff;
};
for (const key in def.events) {
(_subscribeTo as any)[key] = (_: any) => {
return _this.__dispatcher.subscribe(store.id!, _, key);
}
}
(_subscribeTo as any)["All"] = (_: any) => {
return _this.__dispatcher.subscribe(store.id!, _, "ALL");
}
if (def.init) {
store["init"] = def.init;
store["init"]();
}
if (def.nextState) {
store["nextState"] = def.nextState;
}
return {
id : store.id ,
actions : _actions ,
subscribeTo : _subscribeTo ,
getState : () => store["state"] ,
}
}
export const registerStore = _registerStore.bind({ __dispatcher: new Dispatcher() }); |
Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We have written the need
Issue Type: Bug
Following this sample of code :
The syntax color is correct, but if I format it differently, the last statement loses syntax coloration.
VS Code version: Code - Insiders 1.49.0-insider (b6d4fec3714ff897f72c1dab8cc02b7421a8f131, 2020-09-01T05:54:42.740Z)
OS version: Windows_NT x64 10.0.19041
System Info
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
opengl: enabled_on
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Extensions (5)
The text was updated successfully, but these errors were encountered: