How to use the event-target-shim.defineEventAttribute function in event-target-shim

To help you get started, we’ve selected a few event-target-shim 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 channels-frontend / django-channels / src / index.js View on Github external
* Sends a message to the reply channel.
   *
   * @param      {Object}  action     The message
   *
   * @example
   * Stream("myStream", ws).send({prop1: 'value1', prop2: 'value2'});
   */
  send(action) {
      const msg = {
        stream: this.name,
        payload: action,
      };
      this.socket.send(JSON.stringify(msg));
  }
}
defineEventAttribute(Stream.prototype, "open");
defineEventAttribute(Stream.prototype, "close");
defineEventAttribute(Stream.prototype, "error");
defineEventAttribute(Stream.prototype, "message");

/**
 * Bridge between Channels and plain javascript.
 *
 * @example
 * const webSocketBridge = new WebSocketBridge();
 * webSocketBridge.connect("http://example.com/ws/");
 * webSocketBridge.addEventListener("message", function(event) {
 *   console.log(event.data);
 * });
 */
export class WebSocketBridge extends Forwarder {
  constructor(options) {
github channels-frontend / django-channels / src / index.js View on Github external
* @param      {Object}  action     The message
   *
   * @example
   * Stream("myStream", ws).send({prop1: 'value1', prop2: 'value2'});
   */
  send(action) {
      const msg = {
        stream: this.name,
        payload: action,
      };
      this.socket.send(JSON.stringify(msg));
  }
}
defineEventAttribute(Stream.prototype, "open");
defineEventAttribute(Stream.prototype, "close");
defineEventAttribute(Stream.prototype, "error");
defineEventAttribute(Stream.prototype, "message");

/**
 * Bridge between Channels and plain javascript.
 *
 * @example
 * const webSocketBridge = new WebSocketBridge();
 * webSocketBridge.connect("http://example.com/ws/");
 * webSocketBridge.addEventListener("message", function(event) {
 *   console.log(event.data);
 * });
 */
export class WebSocketBridge extends Forwarder {
  constructor(options) {
    super();
    this.socket = null;
github samdenty / cors-bypass / src / API / WebSocket / WebSocket.ts View on Github external
this.dispatchEvent(event)
  }

  private handleWebsocketInfo = ({
    id,
    info
  }: IClientTopics['websocketInfo']) => {
    if (id !== this.id) return

    Object.keys(info).forEach(key => (this[key] = info[key]))
  }
}

defineEventAttribute(WebSocket.prototype, 'close')
defineEventAttribute(WebSocket.prototype, 'error')
defineEventAttribute(WebSocket.prototype, 'message')
defineEventAttribute(WebSocket.prototype, 'open')
github samdenty / cors-bypass / src / API / WebSocket / WebSocket.ts View on Github external
this.dispatchEvent(event)
  }

  private handleWebsocketInfo = ({
    id,
    info
  }: IClientTopics['websocketInfo']) => {
    if (id !== this.id) return

    Object.keys(info).forEach(key => (this[key] = info[key]))
  }
}

defineEventAttribute(WebSocket.prototype, 'close')
defineEventAttribute(WebSocket.prototype, 'error')
defineEventAttribute(WebSocket.prototype, 'message')
defineEventAttribute(WebSocket.prototype, 'open')
github mysticatea / abort-controller / src / abort-signal.ts View on Github external
/**
     * Returns `true` if this `AbortSignal`'s `AbortController` has signaled to abort, and `false` otherwise.
     */
    public get aborted(): boolean {
        const aborted = abortedFlags.get(this)
        if (typeof aborted !== "boolean") {
            throw new TypeError(
                `Expected 'this' to be an 'AbortSignal' object, but got ${
                    this === null ? "null" : typeof this
                }`,
            )
        }
        return aborted
    }
}
defineEventAttribute(AbortSignal.prototype, "abort")

/**
 * Create an AbortSignal object.
 */
export function createAbortSignal(): AbortSignal {
    const signal = Object.create(AbortSignal.prototype)
    EventTarget.call(signal)
    abortedFlags.set(signal, false)
    return signal
}

/**
 * Abort a given signal.
 */
export function abortSignal(signal: AbortSignal): void {
    if (abortedFlags.get(signal) !== false) {
github mysticatea / abort-controller / dist / abort-controller.js View on Github external
constructor() {
        super();
        throw new TypeError("AbortSignal cannot be constructed directly");
    }
    /**
     * Returns `true` if this `AbortSignal`'s `AbortController` has signaled to abort, and `false` otherwise.
     */
    get aborted() {
        const aborted = abortedFlags.get(this);
        if (typeof aborted !== "boolean") {
            throw new TypeError(`Expected 'this' to be an 'AbortSignal' object, but got ${this === null ? "null" : typeof this}`);
        }
        return aborted;
    }
}
eventTargetShim.defineEventAttribute(AbortSignal.prototype, "abort");
/**
 * Create an AbortSignal object.
 */
function createAbortSignal() {
    const signal = Object.create(AbortSignal.prototype);
    eventTargetShim.EventTarget.call(signal);
    abortedFlags.set(signal, false);
    return signal;
}
/**
 * Abort a given signal.
 */
function abortSignal(signal) {
    if (abortedFlags.get(signal) !== false) {
        return;
    }
github channels-frontend / django-channels / src / index.js View on Github external
* @example
   * webSocketBridge.stream('mystream').send({prop1: 'value1', prop2: 'value1'})
   */
  stream(streamName) {
    let stream;
    if (this.streams[streamName] !== undefined) {
      stream = this.streams[streamName];
    } else {
      stream = new Stream(streamName, this.socket);
      this.streams[streamName] = stream;
    }
    return stream;
  }
}
defineEventAttribute(WebSocketBridge.prototype, "open");
defineEventAttribute(WebSocketBridge.prototype, "close");
defineEventAttribute(WebSocketBridge.prototype, "error");
defineEventAttribute(WebSocketBridge.prototype, "message");
github kbumsik / opus-media-recorder / src / OpusMediaRecorder.js View on Github external
].forEach(name => defineEventAttribute(OpusMediaRecorder.prototype, name));
github samdenty / cors-bypass / src / API / WebSocket / WebSocket.ts View on Github external
: new Event(type, rest)

    this.dispatchEvent(event)
  }

  private handleWebsocketInfo = ({
    id,
    info
  }: IClientTopics['websocketInfo']) => {
    if (id !== this.id) return

    Object.keys(info).forEach(key => (this[key] = info[key]))
  }
}

defineEventAttribute(WebSocket.prototype, 'close')
defineEventAttribute(WebSocket.prototype, 'error')
defineEventAttribute(WebSocket.prototype, 'message')
defineEventAttribute(WebSocket.prototype, 'open')
github samdenty / cors-bypass / src / API / WebSocket / WebSocket.ts View on Github external
}

  private handleWebsocketInfo = ({
    id,
    info
  }: IClientTopics['websocketInfo']) => {
    if (id !== this.id) return

    Object.keys(info).forEach(key => (this[key] = info[key]))
  }
}

defineEventAttribute(WebSocket.prototype, 'close')
defineEventAttribute(WebSocket.prototype, 'error')
defineEventAttribute(WebSocket.prototype, 'message')
defineEventAttribute(WebSocket.prototype, 'open')

event-target-shim

An implementation of WHATWG EventTarget interface.

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis