pmndrs / directed

A flexible, minimal scheduler written in TypeScript
MIT License
27 stars 1 forks source link

Add multiple runnables at once #14

Closed pietrovismara closed 4 months ago

pietrovismara commented 4 months ago

I have many runnables with the same options:

schedule.add(updateSettings, { tag: PRE_RENDER_GROUP });
schedule.add(updateAttachmentTextures, { tag: PRE_RENDER_GROUP });
schedule.add(updateTransformMatrices, { tag: PRE_RENDER_GROUP });
schedule.add(updateMaterialBindGroups, { tag: PRE_RENDER_GROUP });
schedule.add(generateVertexBuffersLayout, { tag: PRE_RENDER_GROUP });
schedule.add(updateGeometryBuffers, { tag: PRE_RENDER_GROUP });
schedule.add(updateCameraAspectRatio, { tag: PRE_RENDER_GROUP });
schedule.add(updateCameraMatrices, { tag: PRE_RENDER_GROUP });
schedule.add(createPipelines, { tag: PRE_RENDER_GROUP });
...

It would be more convenient and readable to be able to add them all at once:

schedule.add(
  [
    updateSettings,
    updateAttachmentTextures,
    updateTransformMatrices,
    updateMaterialBindGroups,
    generateVertexBuffersLayout,
    updateGeometryBuffers,
    updateCameraAspectRatio,
    updateCameraMatrices,
    createPipelines,
  ],
  { tag: PRE_RENDER_GROUP }
);
akdjr commented 4 months ago

Added!

Note that if an array of runnables is used, id is not usable as it does not make sense to apply it to multiple runnables. The class version typing is correct (advantage of an options object), functional typing is a bit more complicated. For now, it will just throw an error until I decide on the typing solution.

pietrovismara commented 4 months ago

Thanks and fair enough for the typing! Just FYI I wouldn't mind a separate addMultiple or similar function if that makes typing easier.

pietrovismara commented 4 months ago

oh and could you please create a tag for v0.0.1-alpha.4 so that I can install via npm

akdjr commented 4 months ago

Ended up typing it!

Also created the tag!