figureone
    Preparing search index...

    Class NotificationManager

    Notification manager.

    Publishes notifications of events to subscribers.

    Figure, FigureElement, Recorder, and SlideNavigator all use notification managers for event nofitications.

    Notification managers can also be added to custom objects, but will only publish to subscribers when it is told to publish.

    // Subscribe to the `setTransform` notification of `ball1` to move `ball2`

    // Add ball1 and ball2 to the figure
    const [ball1, ball2] = figure.add([
    {
    name: 'ball1',
    make: 'primitives.polygon',
    sides: 100, radius: 0.5, color: [1, 0, 0, 1],
    },
    {
    name: 'ball2',
    make: 'primitives.polygon',
    sides: 100, radius: 0.3, color: [0, 0, 1, 1],
    },
    ]);

    // Subscribe to ball1's `setTransform` event notification, and use the set
    transform to move ball2 with ball1
    ball1.notifications.add('setTransform', (transform) => {
    ball2.setTransform(transform[0]);
    });

    // Animate ball1 to show ball2 moves with it
    ball1.animations.new()
    .position({ target: [1, 0], duration: 2 })
    .start();
    Index

    Constructors

    Methods

    Constructors

    Methods

    • Subscribe to a notification.

      Parameters

      • name: string

        event notification name

      • callback: string | (() => void)

        to be called when events occur. If string, then FunctionMap of the Figure or FigureElement to which the notification manager is a property of will be used.

      • num: number = -1

        how many notifications the subscriber will receive. num = 1 will mean only the first notification will be sent to the subscriber .num = -1 means all notifications of the event will be sent to the subscriber (-1).

      Returns number

      subscriber id

    • Publish to all subscribers

      Parameters

      • eventName: string
      • payload: any = undefined

        payload to pass to subscribers

      • asArray: boolean = true

        set to true if payload is an array that should be published as an array. Set to false if payload should be published as separated arguments.

      Returns void

    • Remove subscriber from subscription *

      Parameters

      • eventName: string
      • subscriberId: string | number

      Returns void