Skip to content

Instantly share code, notes, and snippets.

@jpommerening
Created April 26, 2017 15:24
Show Gist options
  • Save jpommerening/634e3835d6e5ea40a23d9cfa7fc3b76a to your computer and use it in GitHub Desktop.
Save jpommerening/634e3835d6e5ea40a23d9cfa7fc3b76a to your computer and use it in GitHub Desktop.
// @flow
declare class AxConfiguration {
get( key: string, default?: any ): any;
ensure( key: string ): any;
};
declare type AxContext = {
eventBus: AxEventBus;
features: AxFeatures;
id: AxId;
log: AxLog;
widget: {
area: string;
id: string;
path: string;
}
};
declare class AxEventBus {
addInspector( inspector: Inspector ): Unsubscriber;
subscribe( eventName: string, subscriber: Subscriber, options?: SubscribeOptions ): Unsubscriber;
publish( eventName: string, payload: EventPayload, options?: PublishOptions ): Promise<null>;
publishAndGatherReplies( eventName: string, payload: EventPayload, options?: PublishOptions ): Promise<Array<EventPayload>>;
};
declare class AxHeartbeat {
registerHeartbeatListener( listener: VoidFunction ): Unsubscriber;
onNext( func: VoidFunction ): void;
onBeforeNext( func: VoidFunction ): void;
onAfterNext( func: VoidFunction ): void;
};
declare type AxId = ( suffix?: string ) => string;
declare type AxI18n = I18nApi & {
forFeature( feature: string ): I18nApi;
};
declare class AxLog {
levels: {
[ key: LogLevel|string ]: number;
};
log( level: LogLevel, message: string, replacements?: FormatReplacements ): void;
trace( message: string, replacements?: FormatReplacements ): void;
debug( message: string, replacements?: FormatReplacements ): void;
info( message: string, replacements?: FormatReplacements ): void;
warn( message: string, replacements?: FormatReplacements ): void;
error( message: string, replacements?: FormatReplacements ): void;
fatal( message: string, replacements?: FormatReplacements ): void;
setTag( tag: string, value: string ): void;
addTag( tag: string, value: string ): void;
removeTag( tag: string ): void;
gatherTags(): LogTags;
setLogThreshold( threshold: LogLevel|number ): void;
addLogChannel( channel: LogChannel ): void;
removeLogChannel( channel: LogChannel ): void;
};
declare class AxStorage {
local: StorageApi;
session: StorageApi;
};
declare type AxTooling = ToolingApi & {
forItem( item: ItemMeta ): ToolingApi;
registerItem( item: ItemMeta ): void;
registerDebugInfo( debugInfo: (Object|() => Object) ): void;
};
declare class AxVisibility {
isVisible(): boolean;
onHide( callback: ( false ) => void ): AxVisibility;
onShow( callback: ( true ) => void ): AxVisibility;
onChange( callback: ( boolean ) => void ): AxVisibility;
track( property: string ): AxVisibility;
updateAreaVisibility( visibilityByLocalArea: VisibilityMap, options?: VisibilityOptions ): Promise<null>;
updateWidgetVisibility( visible: boolean ): AxVisibility;
unsubscribe( callback: ( boolean ) => void ): AxVisibility;
};
// formatting
type VoidFunction = VoidFunction;
type IndexedReplacements = any[] | Array<any>;
type NamedReplacements = { [ string ]: any } | Map< string, any >;
type FormatReplacements = IndexedReplacements|NamedReplacements;
// AxI18n
declare class I18nApi {
localize<T>( i18nValue: I18nValue<T>, fallbackValue: void, languageTag?: LanguageTag ): ?T;
localize<T>( i18nValue: I18nValue<T>, fallbackValue: T, languageTag?: LanguageTag ): T;
update( languageTag: LanguageTag ): Promise<null>;
languageTag(): ?LanguageTag;
track( trackingProperty?: string ): void;
format( i18nValue: I18nValue< string >, indexedReplacements?: IndexedReplacements, namedReplacements?: NamedReplacements ): string;
whenLocaleChanged(): string;
};
type I18nValue<T> = { [ lang: LanguageTag ]: T } | Map< LanguageTag, T > | T;
type LanguageTag = string;
// AxEventBus
type EventBusSubscribeAction = {
action: 'subscribe';
source: string;
event: string;
cycleId: number;
};
type EventBusPublishAction = {
action: 'publish';
source: string;
eventObject: EventPayload;
cycleId: number;
};
type EventBusDeliverAction = {
action: 'deliver';
source: string;
target: string;
subsctibedTo: string;
cycleId: number;
};
type EventBusAction =
EventBusSubscribeAction |
EventBusPublishAction |
EventBusDeliverAction;
type EventPayload = any;
type PublishOptions = {
sender?: string|null;
deliverToSender?: boolean;
};
type SubscribeOptions = {
subscriber?: string|null;
clone?: boolean;
};
type EventMeta = {
name: string;
cycleId: number;
sender: string|null;
initiator: null;
options: PublishOptions;
};
type Unsubscriber = VoidFunction;
type Inspector = ( action: EventBusAction ) => void;
type Subscriber = ( event: EventPayload, meta: EventMeta ) => void;
// AxLog
type LogLevel =
'TRACE' |
'DEBUG' |
'INFO' |
'WARN' |
'ERROR' |
'FATAL';
type LogTags = Map<string, string>;
type LogMessage = {
id: number;
level: LogLevel;
text: string;
replacements: FormatReplacements;
time: Date;
tags: LogTags;
sourceInfo: {
file: string;
line: number;
char: number;
};
};
type LogChannel = ( LogMessage ) => void;
// AxStorage
declare class StorageApi {
getItem( key: string ): ?any;
setItem( key: string, item: any ): void;
removeItem( key: string ): void;
};
// AxTooling
type ItemType =
'flow' | 'page' | 'widget';
type ItemMeta = {
instance: string;
item: string;
type: ItemType;
[ ItemType ]: string;
};
declare class ToolingApi {
onChange( func: ( debugInfo: any ) => void ): void;
unsubscribe( func: ( debugInfo: any ) => void ): void;
};
// AxVisibility
type VisibilityMap = { [ string ]: boolean } | Map< string, boolean >;
type VisibilityOptions = { overrideContainer?: boolean };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment