impi icon indicating copy to clipboard operation
impi copied to clipboard

PIXI/Javascript interop

Open nbardy opened this issue 9 years ago • 2 comments

Provide a way to interop with plain javascript objects to allow use of extensions.

Adding a new type seems like a decent way to accomplish this, but it introduce's a mutable value in a immutable map. pixi-lights examples

Native type

{:pixi.object/type :pixi.object.type/native
 :pixi/native (js/PIXI.lights.WebGLDeferredRenderer. 1024 512)
 :pixi.stage 
 {:impi/key :stage
  :pixi.object/type :pixi.object/container
  :pixi.container/children
   [{:pixi.object/type :pixi.object.type/native 
     :pixi/native (js/PIXI.lights.PointLight. 0xffffff 1 1000)}]}}

Another option is adding a hook to add new types

(impi/add-type! :pixi.object.type.lights/point-light
  :pixi.lights/radius #(aset % "radius" %2)
  :pixi.lights/brightness #(aset % "brightness" %2)
  :pixi.lights/radius #(aset % "radius" %2)
  :create [:pixi.lights/color :pixi.lights/brightness :pixi.lights/radius])

Example extensions https://github.com/funkypaul/pixi-filters https://github.com/funkypaul/pixi-extra-filters https://github.com/pixijs/pixi-lights

nbardy avatar Sep 22 '16 16:09 nbardy

I think I'd rather have people adding to the multimethods (or some other mechanism) rather than trying to bring objects into a data structure without any manual coercion.

weavejester avatar Sep 22 '16 18:09 weavejester

Agreed. It's easy enough to just document how to add to the multimethods. But, I'm thinking it would be nice to write a helper function and possibly rewrite some of the implementations with it.

nbardy avatar Sep 22 '16 21:09 nbardy