Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "ancient-cursor/src/lib/cursor"

Index

Type aliases

TCursor

Variables

Const MixedCursor

MixedCursor: TClass<ICursor<ICursorEventsList>> = mixin(Node)

Functions

apply

  • apply(cursor: any, bundle: any): void
  • Apply bundle to cursor and emit 'changed' event.

    example
    
    import { Cursor, apply } from 'ancient-cursor/lib/cursor';
    
    const cursor = new Cursor();
    cursor.exec(true, { a: [{ b: { c: 'd' } }] });
    
    cursor.data; // { a: [{ b: { c: 'd' } }] }
    
    apply( cursor, {
      type: 'set',
      path: 'a.0',
      value: { d: { e: 'f' } },
    });
    
    cursor.data; // { a: [{ d: { e: 'f' } }] }
    

    Parameters

    • cursor: any
    • bundle: any

    Returns void

mixin

  • mixin<T>(superClass: T): any
  • Mixin your Node with Cursor functionality.

    example
    
    import { mixin, ICursorEventsList, ICursor } from 'ancient-cursor/lib/cursor';
    import { Node } from 'ancient-mixins/lib/node';
    import { TClass } from 'ancient-mixins/lib/mixins';
    
    const MixedCursor: TClass<ICursor<ICursorEventsList>> = mixin(Node);
    

    Type parameters

    Parameters

    • superClass: T

    Returns any

spray

  • Spray maintining data by path to many cursors in manager`s list.

    example
    
    import { Cursor, spray } from 'ancient-cursor/lib/cursor';
    import { Manager } from 'ancient-mixins/lib/manager';
    
    const path = 'x.y';
    const _path = path ? `${path}.` : path;
    const parent = new Cursor();
    const sprayed = new Manager();
    
    parent.on('changed', spray(path, sprayed));
    
    parent.apply({
      type: 'set',
      path: `${path}`,
      value: {
        a: { a: 1 },
        b: { b: 2 },
        c: { c: 3 },
      },
    });
    
    parent.get (`${_path}a`) = sprayed.list.nodes.a.data; // true
    parent.get (`${_path}b`) = sprayed.list.nodes.b.data; // true
    parent.get (`${_path}c`) = sprayed.list.nodes.c.data; // true
    

    Parameters

    Returns function

watch

  • watch(__namedParameters: object, paths: TBundlePaths, listener: function): void
  • Listen changes in cursor.data for current path.

    example
    
    import { Cursor, watch } from 'ancient-cursor/lib/cursor';
    
    const cursor = new Cursor();
    cursor.exec(true, { a: [{ b: { c: 'd' } }, { e: { f: 'g' } }] });
    
    cursor.on('changed', ({ bundleChanges }) => {
      watch(bundleChanges, 'a.1', ({ newValue }) => {
        console.log('Watch!');
      });
    });
    
    cursor.apply({
      type: 'set',
      path: 'a.0',
      value: { d: 1 },
    }); // Logs nothing
    
    cursor.apply({
      type: 'set',
      path: 'a.1',
      value: { d: 2 },
    }); // Watch!
    

    Parameters

    Returns void

Generated using TypeDoc