-
-
Notifications
You must be signed in to change notification settings - Fork 116
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
Integration with flowtype #487
Comments
I don't know Flow enough to do this myself but I am sure it is possible for a library to come with some kind of flow definition files for external consomption with flow. |
Don't hesitate to do so. Just know that I probably won't be able to know if what you did is good :). |
@ThomasCrevoisier did you make any progress on this issue ? |
Sorry about giving no news... I looked at it and I don't think the lib is well-suited for a typechecker as we access properties dynamically via strings. |
I've prepared a basic typing, enough for my needs. If anyone would test and/or finish it, I'd polish it and make a PR for flow-typed. declare class Baobab extends events$EventEmitter {
apply(updater: (any) => any): any;
clone(): any;
concat(path: BaobabPath, value: any[]): any;
deepClone(): any;
// deepMerge()
exists(path: BaobabPath): boolean;
get(path: BaobabPath): any;
merge(path: BaobabPath, value: any): any;
// pop
// project
push(path: BaobabPath, value: any): any;
// serialize
set(path: BaobabPath, value: any): any;
// shift
// splice
unset(path: BaobabPath): void;
// unshift
// update()
static dynamicNode: (
...definition: (BaobabPath | ((...paths: any[]) => any))[]
) => BaobabMonkeyDefinition;
static monkey: (
...definition: (BaobabPath | ((...paths: any[]) => any))[]
) => BaobabMonkeyDefinition;
commit(): Baobab;
constructor(initialData?: {}, options?: BaobabOptions): void;
getMonkey(path: BaobabPath): null | BaobabMonkey;
release(): void;
select(): BaobabCursor;
select(path: BaobabPath): BaobabCursor;
toJSON(): any;
toString(): string;
validate(affectedPaths?: string[][]): boolean;
watch(mapping: {[string]: BaobabPath}): BaobabWatcher;
}
declare class BaobabCursor extends events$EventEmitter {}
declare class BaobabMonkey {}
declare class BaobabMonkeyDefinition {}
declare type BaobabOptions = {
asynchronous?: boolean,
autoCommit?: boolean,
immutable?: boolean,
persistent?: boolean,
pure?: boolean,
validate?: (prevState: {}, nextState: {}, affectedPaths: string[][]) => void,
validationBehavior?: 'notify' | 'rollback'
};
declare type BaobabPath = (number | string | {[string]: number | string})[];
declare class BaobabWatcher extends events$EventEmitter {
get(): any;
getCursors(): {[string]: BaobabCursor};
getWatchedPaths(): string[][];
refresh(mapping: {[string]: BaobabPath}): void;
release(): void;
}
declare module 'baobab' {
declare module.exports: typeof Baobab;
} |
It would be really nice to be able to have static type checking with Flow while using baobab.
I didn't push Flow that far though, so I don't know if it's possible at the moment. I could give a try if you are interested :)
The text was updated successfully, but these errors were encountered: