Comments (4)
In my Helpers, I choose to mimic the class implementation with different modules:
module Marker =
let addTo (map: L.Map) (marker: L.Marker) =
marker.addTo(!^map)
|> unbox<L.Marker>
let on (eventType: string) callback (marker: L.Marker) =
marker.on(eventType, callback)
|> unbox<L.Marker>
module Polygon =
let addTo o (polygon : L.Polygon) =
polygon.addTo o
|> unbox<L.Polygon>
let on (eventType, cb) (polygon : L.Polygon) =
polygon.on(eventType, cb)
|> unbox<L.Polygon>
So yes, that can require more work, but as these are classes from the bindings it's more easier for the User to use the binding in a functional way.
In your case, I think the backTo
is good enough for the sample usage. Will see if for a bigger app it's works too.
from samples-pixi.
Thanks for sharing @MangelMaxime I like this way of doing it 👍
from samples-pixi.
@whitetigle To make this more generic and not restrict it to ExtendedSprite
you can use generic constraints:
let attachEvent<'T when 'T :> PIXI.Sprite> (ev: PixiEvent) (handler: EventHandler) (sprite: 'T) =
sprite.on(string ev, handler) :?> 'T
I think
sprite.on
returns a self reference so you shouldn't need to returnsprite
explicitly
from samples-pixi.
Thanks! 👍 I'll try that.
from samples-pixi.
Related Issues (8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from samples-pixi.