Giter Site home page Giter Site logo

Type inference about samples-pixi HOT 4 CLOSED

fable-compiler avatar fable-compiler commented on June 18, 2024
Type inference

from samples-pixi.

Comments (4)

MangelMaxime avatar MangelMaxime commented on June 18, 2024

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.

whitetigle avatar whitetigle commented on June 18, 2024

Thanks for sharing @MangelMaxime I like this way of doing it 👍

from samples-pixi.

alfonsogarciacaro avatar alfonsogarciacaro commented on June 18, 2024

@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 return sprite explicitly

from samples-pixi.

whitetigle avatar whitetigle commented on June 18, 2024

Thanks! 👍 I'll try that.

from samples-pixi.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.