bbc / VideoContext

An experimental HTML5 & WebGL video composition and rendering API.
http://bbc.github.io/VideoContext/
Apache License 2.0
1.32k stars 156 forks source link

Pass node constructors to custom source nodes #191

Closed Sacharified closed 4 years ago

Sacharified commented 4 years ago

Description

This change passes the list of node constructors to custom source nodes.

Motivation

The purpose of this is to allow publishers of custom source nodes which extend VideoContext nodes to not include VideoContext in their bundled code. A mismatch between the package's version and the consumer's version could lead to two different versions of VideoContext being included in the consumer's bundle.

Example:

Package:

export function MyCustomNode(src, gl, renderGraph, currentTime, options, NODES) {
// Doesn't need to import VideoContext to extend a node
  class CustomNode extends NODES.CanvasNode {
    ...
  }

  return new CustomNode(src, gl, renderGraph, currentTime, options);
}

Consumer:

import VideoContext from "videocontext";
import MyCustomNode from "my-custom-vc-node";
const node = MyCustomNode();

The nodes being at the end of the argument list is a little annoying because you can't use rest syntax to pass the args to the class but it keeps this change backwards-compatible.