How to use the @mathigon/core.words function in @mathigon/core

To help you get started, we’ve selected a few @mathigon/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mathigon / textbooks / content / transformations / functions.ts View on Github external
function drawShape($step: Step, $geopad: Geopad, goal: string, shape: string,
                   expand = false) {
  // `shape` should be names of a polygon, segment or line.
  const lines = flatten(
      words(shape).map(s => $geopad.model[s].edges || $geopad.model[s]));

  $geopad.setActiveTool('line');

  $geopad.waitForPaths(lines, {
    onCorrect(path, i) {
      if (expand) expandSegment($geopad, path.points, lines[i]);
    },
    onIncorrect() {
      $step.addHint('incorrect', {force: true});
    },
    onHint() {
      $step.addHint('draw-hint', {force: true});
    },
    onComplete(afterError) {
      if (!afterError) $step.addHint('correct');
      $step.score(goal);
github mathigon / boost.js / src / events.ts View on Github external
export function bindEvent($el: ElementView, event: string, fn: EventCallback,
                          options?: EventListenerOptions) {
  if (event in aliases) {
    const events = words(aliases[event]);
    // Note that the mouse event aliases don't pass through makeMouseEvent()!
    for (const e of events) $el._el.addEventListener(e, fn, options);
  } else if (event in customEvents) {
    customEvents[event]($el);
  } else {
    $el._el.addEventListener(event, fn, options);
  }
}
github mathigon / boost.js / src / elements.js View on Github external
off(events, callback) {
    for (const e of words(events)) removeEvent(this, e, callback);
  }
github mathigon / boost.js / src / elements.js View on Github external
trigger(events, args = {}) {
    for (const e of words(events)) {
      if (!this._events[e]) return;
      for (const fn of this._events[e]) fn.call(this, args);
    }
  }
github mathigon / boost.js / src / elements.js View on Github external
on(events, callback, options = undefined) {
    for (const e of words(events)) createEvent(this, e, callback, options);
  }