Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalized mappings / Top-level function #13

Closed
10 of 11 tasks
edemaine opened this issue Feb 1, 2017 · 1 comment
Closed
10 of 11 tasks

Generalized mappings / Top-level function #13

edemaine opened this issue Feb 1, 2017 · 1 comment
Labels

Comments

@edemaine
Copy link
Owner

edemaine commented Feb 1, 2017

Does it make sense for top-level function to be (key) -> -> ...@ is context...? Why not (key) -> ...@ is context...? Or, for that matter, just -> ...@ is context, @key is key...?

The new proposed generalized form of mapping can be

  • Preact VDOM (modern way to write SVG),
  • a raw string (for the old-school way of writing SVG),
  • a filename string (as a shortcut for including images or SVG from files),
  • an object (dictionary, as shorthand for (key) -> obj[key]),
  • a Map as a modern alternative to object,
  • an array (for multiple symbols Keys expanding to multiple <symbol>s #33), or
  • a function whose return value can be any of these, recursively.
    • Functions would be called with arguments (key, context), and for backward compatibility, with this set to the context as well.

This would provide backward compatibility with -> -> ... and X: -> ..., but would remove the need for the double ->. It would also allow interesting/weird things like

->
  if @i == 0  # use different object mapping on first row
    x: ...
    y: ...
  else
    x: ...
    y: ...
  • new Mapping takes one of the above as an argument
  • Mapping.prototype.lookup recursively evaluates a symbol given context
  • Require object or Map or function at top level (string/VDOM/array, which don't depend on key at all, allowed only at deeper levels).

Static Symbols

The one thing this approach would lose is a way to express static symbols defined by a function. Strings and Preact VDOM directly in an object would still be static. But I don't think functions that return things other than functions is too common in practice, because it isn't very easy. And I hope that rerunning in that case won't cost too much in performance. But I think we could replace it with:

  • svgtiler.static(foo) could wrap foo in a declaration that its contents do not depend on context at all. This would make it easier to specify when desired for efficiency, also in a conditional or something. And it would work to specify some parts of an array are static while others are not. [This is the equivalent of untrack in Solid.]
  • context.amStatic() would be another way within a function, but this doesn't let us distinguish individual items in an array.

More broadly, fine-grained reactivity is a better solution if we want to optimize further than the static/dynamic line.

Needs to be paired with #50.

@edemaine edemaine changed the title Top-level function Generalized mappings / Top-level function Feb 1, 2017
@edemaine
Copy link
Owner Author

edemaine commented Jun 9, 2019

I think another way to phrase this is that, for js/coffee mappings defined by a function, it'd be natural to think of everything as a universal dynamic symbol. This requires refactoring the "symbol cache" from individual DynamicSymbols to... The Mapping? The renderer? This has the added advantage of detecting duplicate symbols with different keys.

[moved this to #50]

@edemaine edemaine mentioned this issue Aug 1, 2022
5 tasks
edemaine added a commit that referenced this issue Aug 13, 2022
* All function mappings are now automatically dynamic;
  no need to wrap in a second layer of function.
* Can force old static behavior (for efficiency)
  via `svgtiler.static` wrapper.
* Support mapping defined by `Map` or `WeakMap`
edemaine added a commit that referenced this issue Aug 13, 2022
* Support mapping defined by `Map` or `WeakMap`
* All function mappings are now automatically dynamic;
  no need to wrap in a second layer of function.
* Can force old static behavior (for efficiency)
  via `svgtiler.static` wrapper, cached at `Mapping` level.
* Function mappings get `context` second argument in addition to `this`.
* `Context` object now shared throughout each drawing
  (so you could store extra drawing-specific data there).
* API change: `Context` no longer has `symbols`, `symbol`, `data`,
  `filename`, or `subname` attributes.  For the latter three,
  use `drawing.data`, `drawing.filename`, or `drawing.subname`.
* API change: No more `Symbol`, `StaticSymbol`, or `DynamicSymbol` class
  (in particular, there was a name conflict with JS's `Symbol`)
* API change: `Input` constructor supports direct loading of data
  (for easy manual creation) or immediate parsing of file data,
  as well as option setting.  This will help with #34.
* New `Tile` class represents an expanded (and possibly parsed)
  tile `<symbol>` (roughly what `Symbol` was before).
* Tile caching/deduplication now within the renderer, not by `Symbol`
  (fix #50), enabling re-use when multiple symbols expand to the same SVG.
* Fix: Don't fill in `<image>` `width`/`height` when both already set.
* Fix: Use `hasOwnProperty` and `Set`s to avoid accidentally matching
  e.g. `toString`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant