(
): HTMLElement {
// Initialize the context if it is not provided.
const { width = 640, height = 480, depth = 0 } = options;
- const keyed = inferKeys(options);
+ // Preprocessing here, such as syntactic sugar.
+ const preprocessedOption = preprocessOption(options);
+ const keyed = inferKeys(preprocessedOption);
const {
canvas = Canvas(width, height),
emitter = new EventEmitter(),
diff --git a/src/utils/flow.ts b/src/utils/flow.ts
new file mode 100644
index 0000000000..924dc0042b
--- /dev/null
+++ b/src/utils/flow.ts
@@ -0,0 +1,13 @@
+type FlowFunction = (param: P) => P;
+
+/**
+ * 类似 lodash.flow 的方法
+ * @param flows
+ */
+export function flow
(...flows: FlowFunction
[]): FlowFunction
{
+ return (param: P) => {
+ return flows.reduce((result: P, f: FlowFunction
) => {
+ return f(result);
+ }, param);
+ };
+}