Flare

flare

npm install flare
yarn add flare

flare

Table of contents

Type Aliases

Functions

Type Aliases

Flare

Ƭ Flare<A>: Object

The basic building block of a Flare UI, capable of providing a value when queried and invoking some upstream handler when the value changes

Type parameters

NameDescription
AThe value the Flare produces

Type declaration

NameTypeDescription
_tag"Flare"Tags the object as a Flare.
make() => { query: () => A ; render: VoidFunctionComponent<{ onChange: () => void }> }Initializes the Flare.

Unflare

Ƭ Unflare<F>: F extends Flare<infer A> ? A : never

A utility type that extracts the type parameter A from a Flare<A>

Remarks

A Flare<A> produces values of type A. The A type can sometimes be useful, for example to annotate function parameters where TypeScript struggles to infer types.

Type parameters

NameDescription
FThe Flare<A> from which to extract A

Functions

ap

ap<A, B>(fa): (fab: Flare<(a: A) => B>) => Flare<B>

Applies a function to a value within a Flare context.

Type parameters

NameDescription
AThe value to which to apply the function
BThe return value of the function

Parameters

NameTypeDescription
faFlare<A>The Flare that produces the original value

Returns

fn

A Flare that produces the result of the function application

▸ (fab): Flare<B>

Parameters
NameType
fabFlare<(a: A) => B>
Returns

Flare<B>


chain

chain<A, B>(afb): (fa: Flare<A>) => Flare<B>

Composes Flares in a sequence.

Type parameters

NameDescription
AThe value produced by the first Flare
BThe value produced by the second Flare

Parameters

NameTypeDescription
afb(a: A) => Flare<B>The function to apply to the output of the first Flare to produce the second Flare

Returns

fn

The Flare resulting from the composition

▸ (fa): Flare<B>

Parameters
NameType
faFlare<A>
Returns

Flare<B>


checkbox

checkbox(options): Flare<boolean>

Creates a Flare that renders as a checkbox control.

Parameters

NameTypeDescription
optionsObjectCheckbox options
options.initialbooleanInitial checked state
options.label?stringCheckbox label

Returns

Flare<boolean>

The Flare that was created


comboBox

comboBox<A, C>(options): Flare<A>

Creates a Flare that renders as a combo box.

Type parameters

NameTypeDescription
AAThe value that the combo box produces
Cextends { optionToString?: undefined } | { optionToString: (option: A) => string }An additional optionToString option, required to convert A to string when it doesn't already extend string

Parameters

NameTypeDescription
options{ initial: A ; label?: string ; options: readonly A[] } & CCombo box options

Returns

Flare<A>

The Flare that was created


ifElse

ifElse<A, B>(a, b): (cond: boolean) => Flare<A | B>

Combines two Flares into one, producing the value from the original Flare that corresponds to the boolean expression provided.

Type parameters

NameDescription
AThe value produced by the first Flare
BThe value produced by the second Flare

Parameters

NameTypeDescription
aFlare<A>The value produced by the first Flare
bFlare<B>The value produced by the second Flare

Returns

fn

The first Flare when the boolean expession is true; otherwise, the second Flare

▸ (cond): Flare<A | B>

Parameters
NameType
condboolean
Returns

Flare<A | B>

Remarks

This is typically used with chain.


map

map<A, B>(ab): (fa: Flare<A>) => Flare<B>

Applies a function to a Flare to change its output.

Type parameters

NameDescription
AThe value produced by the original Flare
BThe value produced by the modified Flare

Parameters

NameTypeDescription
ab(a: A) => BThe function to apply to the output of the original Flare

Returns

fn

A Flare that produces the result of the function application

▸ (fa): Flare<B>

Parameters
NameType
faFlare<A>
Returns

Flare<B>


match

match<M>(map): M extends Record<string | number, Flare<infer A>> ? (key: keyof M) => Flare<A> : never

Combines multiple Flares into one, producing the value from the original Flare that corresponds to the expression provided.

Type parameters

NameDescription
MThe map of Flares from which to select

Parameters

NameTypeDescription
mapMThe map of Flares from which to select

Returns

M extends Record<string | number, Flare<infer A>> ? (key: keyof M) => Flare<A> : never

A function that returns the Flare from the map corresponding to the specified key

Remarks

This is typically used with chain.


of

of<A>(a): Flare<A>

Lifts a value into a Flare context.

Type parameters

NameDescription
AThe value to lift

Parameters

NameTypeDescription
aAThe value to lift

Returns

Flare<A>

A Flare that produces the specified value a


radioGroup

radioGroup<A, C>(options): Flare<A>

Creates a Flare that renders as a group of radio buttons.

Type parameters

NameTypeDescription
AAThe value that the radio button group produces
Cextends { optionToString?: undefined } | { optionToString: (option: A) => string }An additional optionToString option, required to convert A to string when it doesn't already extend string

Parameters

NameTypeDescription
options{ initial: A ; label?: string ; options: readonly A[] } & CRadio group options

Returns

Flare<A>

The Flare that was created


resizableList

resizableList<A>(options): Flare<A[]>

Creates a Flare that renders as a resizable list of Flares.

Type parameters

Name
A

Parameters

NameTypeDescription
optionsObjectResizable list options
options.initial?Flare<A>[]The initial list of Flares
options.itemFlare<A>The Flare used each time an item is added to the list
options.maxLength?numberThe maximum length of the list
options.minLength?numberThe minimum length of the list

Returns

Flare<A[]>

The Flare that was created


runFlare

runFlare(controlsElementId, targetElementId, flare): void

Runs the specified Flare, rendering its HTML output to the target element.

Parameters

NameTypeDescription
controlsElementIdstringThe id of the element in which to render the Flare controls
targetElementIdstringThe id of the element in which to render the HTML output
flareFlare<HTML>The Flare to run

Returns

void


runFlareWith

runFlareWith<A>(controlsElementId, handler, flare): void

Runs the specified Flare, invoking the handler on each change.

Type parameters

NameDescription
AThe value produced by the Flare

Parameters

NameTypeDescription
controlsElementIdstringThe id of the element in which to render the Flare controls
handler(a: A) => voidThe callback function to invoke each time the value changes
flareFlare<A>The Flare to run

Returns

void


slider

slider(options): Flare<number>

Creates a Flare that renders as a slider.

Parameters

NameTypeDescription
optionsObjectSlider options
options.initialnumberInitial slider state
options.label?stringSlider label
options.max?numberMaximum selectable value
options.min?numberMinimum selectable value
options.step?numberThe granularity of the slider value

Returns

Flare<number>

The Flare that was created


spinButton

spinButton(options): Flare<number>

Creates a Flare that renders as a spin button.

Parameters

NameTypeDescription
optionsObjectSpin button options
options.initialnumberInitial spin button state
options.label?stringSpin button label
options.max?numberMaximum selectable value
options.min?numberMinimum selectable value
options.step?numberThe granularity of the spin button value

Returns

Flare<number>

The Flare that was created


switch_

switch_(options): Flare<boolean>

Creates a Flare that renders as a switch.

Parameters

NameTypeDescription
optionsObjectSwitch options
options.initialbooleanInitial switch state
options.label?stringSwitch label

Returns

Flare<boolean>

The Flare that was created


textBox

textBox(options): Flare<string>

Creates a Flare that renders as a text box.

Parameters

NameTypeDescription
optionsObjectText box options
options.initialstringInitial text box state
options.label?stringText box label
options.nonEmpty?boolean-

Returns

Flare<string>

The Flare that was created

Flare

Applicative-style UIs in TypeScript

Get started
npm install flare
yarn add flare

Flare