Closed edemaine closed 2 years ago
The first part doesn't seem consistent with the new split of beforeRender
into init
and preprocess
. The constructor would naturally be an alternative to init
, but then the object lifetime doesn't correspond to a render.
However, preprocess
and postprocess
are called with this
set to the Render
instance, so there already is a somewhat natural place to put data... but it can't be set in init
.
The second part is replaced by #100.
Yevhenii suggested an alternative form for specifying a mapping:
The cool thing about this is that the lifecycle of class instances corresponds to each drawing/render, so you have a clear place to initialize drawing-specific things, and a clear place (the instance) to store drawing-specific data. Maybe you can do interesting things with inheritance too?
Otherwise it doesn't seem to offer much benefit. So I'm wondering about adding it as another option for how to specify mapping data, for complicated uses of
beforeRender
/afterRender
.A different but related approach is for
import * from './mapping.js'
to give the desired objects. Something like this:One advantage is that creating a custom mapping is really easy: just build an object
{init: ..., preprocess: ..., default: ...}
.Another cool feature is that then
svgtiler('map.js')
is equivalent tosvgtiler(require('./map.js'))
. But this equivalence is incompatible with top-level effects likesvgtiler.preprocess
andsvgtiler.background
. We could redefinesvgtiler.background
to only be callable withinpostprocess
callbacks, with the meaning "add background rect now"; or keep its scheduling behavior, but restrict to running within a render (eitherpreprocess
orpostprocess
).