Variable CardboardConst

Cardboard: {
    allTags: any;
    CEvent: any;
    CMappedEvent: any;
    CTag: any;
    Observable: any;
    StyleManager: any;
    arraysEqual: ((a?, b?) => boolean);
    camelToDash: ((str) => any);
    checkInitialized: (() => void);
    clearMountPoints: (() => void);
    compute: (<T, K>(other, transform) => IObservable<K>);
    computeMultiple: (<T, K>(observables, transform) => IObservable<K>);
    context: CardboardContext;
    createGlobalObserver: (() => {
        onAdded: CEvent<Node>;
        onRemoved: CEvent<Node>;
    });
    createObservable: (<T>(val, destroyer?) => IObservable<T>);
    deepEquals: ((a, b) => boolean);
    equalTo: (<T>(observable, val) => IObservable<boolean>);
    genBlock: ((selector, style) => string);
    genBlockContent: ((selector, style) => string[]);
    genCss: ((styleSheet) => string);
    getMountPoint: (() => undefined | CTag);
    getValue: (<T>(val) => T);
    grab: (<T, K>(observable, key, defaultVal?) => IObservable<undefined | T[K]>);
    greaterThan: ((observable, val?) => IObservable<boolean>);
    greaterThanOr: ((observable, val?) => IObservable<boolean>);
    init: ((options?) => CTag);
    isArray: ((obj) => boolean);
    isEmpty: (<T>(observable) => IObservable<boolean>);
    isInitialized: (() => boolean);
    isObject: ((obj) => boolean);
    isObservable: ((obj) => boolean);
    lessThan: ((observable, val?) => IObservable<boolean>);
    lessThanOr: ((observable, val?) => IObservable<boolean>);
    listState: (<T>(initialData) => {
        add: ((item) => void);
        addAt: ((item, index) => void);
        length: IObservable<number>;
        remove: any;
        removeWhere: any;
        get list(): State<State<T>[]>;
        get listValue(): State<T>[];
    });
    mappedEvent: (<T>() => CMappedEvent<T>);
    mountPoint: ((tag) => CTag);
    notEmpty: (<T>(observable) => IObservable<boolean>);
    notEqualTo: (<T>(observable, val) => IObservable<boolean>);
    removeFromList: (<T>(item, list?) => boolean);
    resetMountPoints: (() => void);
    restoreMountPoint: (() => void);
    singleEvent: (<T>() => CEvent<T>);
    state: (<T>(initialValue) => State<T>);
    stateAdd: (<T>(state, item) => void);
    stateAddAt: (<T>(state, item, index) => void);
    stateRemove: (<T>(state, item) => void);
    stateRemoveWhere: (<T>(state, cb) => void);
    swapItems: ((array, from, to) => any[]);
    tag: ((arg0, children?, mountToParent?) => CTag);
    text: (<T, K>(textTemplate, obj?) => Node);
    val: (<T>(val, ...args) => T);
    version: string;
    withLifecycle: ((tag, handler) => CTag);
    withMountPoint: ((tag, scopedCallback) => void);
    generateUID(idNumber?) => string;
    onLifecycle(tag, onMounted?, onUnmounted?, beforeUnmounted?) => void;
    uuidv4() => string;
} = ...

Type declaration

  • arraysEqual: ((a?, b?) => boolean)
      • (a?, b?): boolean
      • Parameters

        • Optional a: any[]
        • Optional b: any[]

        Returns boolean

  • camelToDash: ((str) => any)
      • (str): any
      • Parameters

        • str: any

        Returns any

  • checkInitialized: (() => void)
      • (): void
      • Returns void

  • clearMountPoints: (() => void)
      • (): void
      • Restores all mount points. There will be no mount points tag after calling this function.

        Returns void

  • compute: (<T, K>(other, transform) => IObservable<K>)
      • <T, K>(other, transform): IObservable<K>
      • Creates a new Observable whose value is derived from another Observable. The new Observable automatically updates and notifies listeners whenever the source Observable changes.

        Type Parameters

        • T

        • K

        Parameters

        • other: IObservable<T>
        • transform: ((val) => K)
            • (val): K
            • Parameters

              • val: T

              Returns K

        Returns IObservable<K>

        Example

        const value = createObservable(2);
        // Create a derived observable that is true if value > 5
        const isGreater = compute(value, (v) => v > 5);
        // isGreater.value == false
        value.dispatch(6);
        // isGreater.value == true
  • computeMultiple: (<T, K>(observables, transform) => IObservable<K>)
      • <T, K>(observables, transform): IObservable<K>
      • Type Parameters

        Parameters

        • observables: [...T[]]
        • transform: ((...v) => K)
            • (...v): K
            • Parameters

              Returns K

        Returns IObservable<K>

  • context: CardboardContext
  • createGlobalObserver: (() => {
        onAdded: CEvent<Node>;
        onRemoved: CEvent<Node>;
    })
      • (): {
            onAdded: CEvent<Node>;
            onRemoved: CEvent<Node>;
        }
      • Returns {
            onAdded: CEvent<Node>;
            onRemoved: CEvent<Node>;
        }

  • createObservable: (<T>(val, destroyer?) => IObservable<T>)
  • deepEquals: ((a, b) => boolean)
      • (a, b): boolean
      • Parameters

        • a: any
        • b: any

        Returns boolean

  • equalTo: (<T>(observable, val) => IObservable<boolean>)
  • genBlock: ((selector, style) => string)
      • (selector, style): string
      • Parameters

        Returns string

  • genBlockContent: ((selector, style) => string[])
      • (selector, style): string[]
      • Parameters

        Returns string[]

  • genCss: ((styleSheet) => string)
  • getMountPoint: (() => undefined | CTag)
      • (): undefined | CTag
      • Returns the current mountPoint CTag. See mountPoint for more information.

        Returns undefined | CTag

  • getValue: (<T>(val) => T)
      • <T>(val): T
      • Type Parameters

        • T

        Parameters

        Returns T

  • grab: (<T, K>(observable, key, defaultVal?) => IObservable<undefined | T[K]>)
      • <T, K>(observable, key, defaultVal?): IObservable<undefined | T[K]>
      • compute an observable and return a new Observable that is equal to some property of the original Observable

        Type Parameters

        • T

        • K extends string | number | symbol

        Parameters

        • observable: IObservable<T>
        • key: K
        • Optional defaultVal: T[K]

        Returns IObservable<undefined | T[K]>

  • greaterThan: ((observable, val?) => IObservable<boolean>)
  • greaterThanOr: ((observable, val?) => IObservable<boolean>)
  • init: ((options?) => CTag)
      • (options?): CTag
      • It initializes the framework & makes the body tag the mount point (mountPoint). You can pass in a selector for an element you want to be the default tag ("body" by default).

        Parameters

        • options: {
              selector: string;
          } = ...
          • selector: string

        Returns CTag

  • isArray: ((obj) => boolean)
      • (obj): boolean
      • Parameters

        • obj: any

        Returns boolean

  • isEmpty: (<T>(observable) => IObservable<boolean>)
  • isInitialized: (() => boolean)
      • (): boolean
      • Returns boolean

  • isObject: ((obj) => boolean)
      • (obj): boolean
      • Parameters

        • obj: any

        Returns boolean

  • isObservable: ((obj) => boolean)
      • (obj): boolean
      • Check if a given object obj is a Observable

        Parameters

        • obj: any

        Returns boolean

  • lessThan: ((observable, val?) => IObservable<boolean>)
  • lessThanOr: ((observable, val?) => IObservable<boolean>)
  • listState: (<T>(initialData) => {
        add: ((item) => void);
        addAt: ((item, index) => void);
        length: IObservable<number>;
        remove: any;
        removeWhere: any;
        get list(): State<State<T>[]>;
        get listValue(): State<T>[];
    })
      • <T>(initialData): {
            add: ((item) => void);
            addAt: ((item, index) => void);
            length: IObservable<number>;
            remove: any;
            removeWhere: any;
            get list(): State<State<T>[]>;
            get listValue(): State<T>[];
        }
      • listState creates a reactive list of values that can be used with tags to manage dynamic and reactive apps. It wraps each item with a State (aka. IObservable) to allow for individual item reactivity.

        Type Parameters

        • T

        Parameters

        • initialData: T[]

        Returns {
            add: ((item) => void);
            addAt: ((item, index) => void);
            length: IObservable<number>;
            remove: any;
            removeWhere: any;
            get list(): State<State<T>[]>;
            get listValue(): State<T>[];
        }

        • add: ((item) => void)
            • (item): void
            • Parameters

              • item: T

              Returns void

        • addAt: ((item, index) => void)
            • (item, index): void
            • Parameters

              • item: T
              • index: number

              Returns void

        • length: IObservable<number>
        • remove: any
        • removeWhere: any
        • get list(): State<State<T>[]>

          The reactive list of items. Each item is wrapped in a State to allow for individual reactivity.

        • get listValue(): State<T>[]

          The raw list of items.

        See

        https://github.com/nombrekeff/cardboard-js/wiki/ListState

        Example

        const myList = listState([1, 2, 3]);

        myList.add(4);
        myList.addAt(0, 0);
        myList.remove(2);
        myList.removeWhere(item => item === 3);
        const listValues = myList.listValue;
        const listLength = myList.length;

        // Listen to changes in the list
        myList.list.changed(() => {
        // List has changed
        });
  • mappedEvent: (<T>() => CMappedEvent<T>)
  • mountPoint: ((tag) => CTag)
      • (tag): CTag
      • Makes the given tag the mount point. This means that when other tags are created with "mountToParent" or (using <tag_name>.mount(), tag('<tag_name>', [], true)), they will be added as children of this tag. You can call mountPoint multiple times, and the last mount point tag will be used. Then when you've finished, you can call restoreMountPoint to go back to the previously mounted tag if there is one. You can clear all mount points using clearMountPoints.

        Parameters

        Returns CTag

        Example

        mountPoint(div()); // Div 1
        div.mount(); // added as child of div
        p.mount(); // added as child of div

        mountPoint(div()); // Div 2
        div.mount(); // added as child of new div
        p.mount(); // added as child of new div

        restoreMountPoint(); // Back to div 1
        clearMountPoints(); // Clears all mount points, no mount point after this call
  • notEmpty: (<T>(observable) => IObservable<boolean>)
  • notEqualTo: (<T>(observable, val) => IObservable<boolean>)
  • removeFromList: (<T>(item, list?) => boolean)
      • <T>(item, list?): boolean
      • Removes an item from an array if it exists. It returns whether it was removed or not

        Type Parameters

        • T

        Parameters

        • item: T
        • Optional list: T[]

        Returns boolean

  • resetMountPoints: (() => void)
      • (): void
      • Clears the mount point history and resets the mount point to the first one. This means that the mount point will be the first tag that was mounted, and all other mount points will be cleared.

        Returns void

  • restoreMountPoint: (() => void)
      • (): void
      • Restore the currently mounted tag (mountPoint). Goes back in the stack of mount points tags. If there is no previous mount point tag, it will not do anything.

        Returns void

  • singleEvent: (<T>() => CEvent<T>)
  • state: (<T>(initialValue) => State<T>)
      • <T>(initialValue): State<T>
      • state creates a reactive value that can the be used with tags to create dinamic and reactive apps.

        Type Parameters

        • T

        Parameters

        • initialValue: T

        Returns State<T>

        See

        https://github.com/nombrekeff/cardboard-js/wiki/State

        Example

        const count = state(0);
        count.changed(() => { ... });
        count.dispatch(2);
        count.value++;

        div().hideIf(count);
        div().disableIf(count);
        div(template('Count is: $count', { count: count }));
  • stateAdd: (<T>(state, item) => void)
      • <T>(state, item): void
      • stateAdd adds an item to a reactive list. It creates a new array with the existing items and the new item, then updates the state.

        Type Parameters

        • T

        Parameters

        • state: State<T[]>
        • item: T

        Returns void

        Example

        const myList = state([]);
        stateAdd(myList, 'new item');
  • stateAddAt: (<T>(state, item, index) => void)
      • <T>(state, item, index): void
      • stateAddAt adds an item to a reactive list at a specific index. It creates a new array with the existing items and the new item at the specified index, then updates the state.

        Type Parameters

        • T

        Parameters

        • state: State<T[]>
        • item: T
        • index: number

        Returns void

        Example

        const myList = state([]);
        stateAddAt(myList, 'new item', 0);
  • stateRemove: (<T>(state, item) => void)
      • <T>(state, item): void
      • stateRemove removes a specific item from a reactive list. It finds the index of the item in the list and calls stateRemoveWhere to remove it.

        Type Parameters

        • T

        Parameters

        • state: State<T[]>
        • item: T

        Returns void

        Example

        const myList = state([1, 2, 3, 4]);
        stateRemove(myList, 2); // Removes the item with value 2
  • stateRemoveWhere: (<T>(state, cb) => void)
      • <T>(state, cb): void
      • stateRemoveWhere removes items from a reactive list based on a callback function. It filters the list and updates the state with the remaining items.

        Type Parameters

        • T

        Parameters

        • state: State<T[]>
        • cb: ((item, index) => boolean)
            • (item, index): boolean
            • Parameters

              • item: T
              • index: number

              Returns boolean

        Returns void

        Example

        const myList = state([1, 2, 3, 4]);
        stateRemoveWhere(myList, (item) => item % 2 === 0); // Removes even numbers
  • swapItems: ((array, from, to) => any[])
      • (array, from, to): any[]
      • Parameters

        • array: any[]
        • from: number
        • to: number

        Returns any[]

  • tag: ((arg0, children?, mountToParent?) => CTag)
      • (arg0, children?, mountToParent?): CTag
      • This function can do the following based on the first argument:

        • create a tag if you provide a tag name: (div, abbr, custom-tag, ...),
        • wrap around an existing element in the page if you pass in a selector: ('(body)', '(#id)', '(.class)'), any selector is allowed.
        • wrap around an element passed in

        Then it can receive a list of children to be added. Receives a third argument for mounting this tag to the currently mounted tag (context.mountPoint).

        Parameters

        • arg0: string | HTMLElement
        • children: TagChildren = []
        • mountToParent: boolean = false

        Returns CTag

        Example

        tag('div');
        tag('(body)');
        tag('(.someclass)');
        tag(document.querySelector('#something'));
  • text: (<T, K>(textTemplate, obj?) => Node)
      • <T, K>(textTemplate, obj?): Node
      • Create a TextNode from text, and optionally reacts to a IObservable, interpolating the defined variables in the text each time the state changes.

        If you provide a IObservable as the second argument, the text will act as a template and can reference properties in the state: $count, $someValue.

        When the state properties changes, the text node will be automatically updated with the new text. Only the properties that are referenced in the template will be listened to.

        NOTE If you're not interpolating, and dont need to change the text, you can directly pass in a string ('string') instead of (text('string')).

        Type Parameters

        Parameters

        Returns Node

        See

        https://github.com/nombrekeff/cardboard-js/wiki/Managing-Text

        Example

        const st = state({ count: 0 });

        p(text('Raw text!'));
        p(text(`Count: $count`, st));
  • val: (<T>(val, ...args) => T)
      • <T>(val, ...args): T
      • Type Parameters

        • T

        Parameters

        • val: T | ((...args) => T)
        • Rest ...args: any[]

        Returns T

  • version: string
  • withLifecycle: ((tag, handler) => CTag)
      • (tag, handler): CTag
      • withLifecycle is a utility function that adds lifecycle hooks to a Cardboard tag.

        Will call handler.mounted when the element is added to the DOM.
        Then call handler.beforeUnmount before the element is removed from the DOM.
        Finally call handler.unmounted when the element is removed from the DOM.

        Parameters

        • tag: CTag
        • handler: AtLeastOne<{
              beforeUnmounted?: ((tag) => boolean | Promise<boolean>);
              mounted?: ((tag) => boolean | Promise<boolean>);
              unmounted?: ((tag) => void);
          }>

        Returns CTag

        Example

        const myTag = withLifecycle(
        div('Hello World'),
        {
        mounted: (tag) => {
        console.log('Mounted:', tag);
        return true; // or false to prevent mounting
        },
        unmounted: (tag) => {
        console.log('Unmounted:', tag);
        },
        beforeUnmount: (tag) => {
        console.log('Before Unmount:', tag);
        return true; // or false to prevent unmounting
        },
        }
        );
  • withMountPoint: ((tag, scopedCallback) => void)
      • (tag, scopedCallback): void
      • Sets the mount point to the given tag, calls the scoped callback, and then restores the mount point. Useful for creating a temporary mount point for a specific tag, and then restoring the previous mount point.

        Parameters

        Returns void

  • generateUID:function
    • Generates a unique ID for a Cardboard tag. If an idNumber is provided, it will return a string in the format c_<idNumber>. If no idNumber is provided, it will generate a random UUID in the format c_xxxxxxxxxx.

      Parameters

      • Optional idNumber: number

      Returns string

      A unique ID string for a Cardboard tag.

  • onLifecycle:function
    • Will call {mounted} when the element is added to the DOM. And will call {beforeUnmounted} before the element is removed from the DOM. Finally will call {onUnmounted} when the element is removed from the DOM.

      Parameters

      • tag: CTag
      • Optional onMounted: ((tag) => boolean | Promise<boolean>)
          • (tag): boolean | Promise<boolean>
          • Parameters

            Returns boolean | Promise<boolean>

      • Optional onUnmounted: ((tag) => void)
          • (tag): void
          • Parameters

            Returns void

      • Optional beforeUnmounted: ((tag) => boolean | Promise<boolean>)
          • (tag): boolean | Promise<boolean>
          • Parameters

            Returns boolean | Promise<boolean>

      Returns void

  • uuidv4:function
    • Returns string

Generated using TypeDoc