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

Remove dependency on Fable.Extras #13

Open
JaggerJo opened this issue Mar 7, 2022 · 1 comment
Open

Remove dependency on Fable.Extras #13

JaggerJo opened this issue Mar 7, 2022 · 1 comment

Comments

@JaggerJo
Copy link

JaggerJo commented Mar 7, 2022

Is your feature request related to a problem?

Fable.Extras does not compile with the latest fable version.

Describe the solution you'd like

Only a few functions from Fable.Extras are actually used. I'd suggest to get rid of the dependency.

Describe alternatives you've considered

Updating Fable.Extras to work with the latest Fable version.

Additional context

This is enough to make Feliz.Recoil work without the Fable.Extras dependency.

namespace Feliz.Recoil

open Fable.Core
open FSharp.Core
open Fable.Core.JsInterop

[<Erase; RequireQualifiedAccess>]
module JSe =

    /// Tests to see if the prototype property of a constructor appears
    /// anywhere in the prototype chain of an object.
    ///
    /// This should only be used when working with external code (like bindings).
    [<Emit("$1 instanceof $0")>]
    let instanceOf (ctor: obj) (value: obj) : bool = jsNative

    /// Type checking and equality helpers.
    [<Erase>]
    type is =
        [<Emit("typeof $0 === 'function'")>]
        static member function' (value: obj) : bool = jsNative

        [<Emit("typeof $0 === null")>]
        static member null' (value: obj) : bool = jsNative

        /// Checks if the input is both an object and has a Symbol.iterator.
        [<Emit("typeof $0 === 'object' && !$0[Symbol.iterator]")>]
        static member nonEnumerableObject (value: obj) : bool = jsNative

        /// Normal structural F# comparison, but ignores top-level functions (e.g. Elmish dispatch).
        static member equalsButFunctions (x: 'a) (y: 'a) =
            if obj.ReferenceEquals(x, y) then
                true
            elif is.nonEnumerableObject x && not(isNull(box y)) then
                let keys = JS.Constructors.Object.keys x
                let length = keys.Count
                let mutable i = 0
                let mutable result = true
                while i < length && result do
                    let key = keys.[i]
                    i <- i + 1
                    let xValue = x?(key)
                    result <- is.function' xValue || xValue = y?(key)
                result
            else
                (box x) = (box y)

        /// Performs a memberwise comparison where value types and strings are compared by value,
        /// and other types by reference.
        static member equalsWithReferences (x: 'a) (y: 'a) =
            if obj.ReferenceEquals(x, y) then
                true
            elif is.nonEnumerableObject x && not(isNull(box y)) then
                let keys = JS.Constructors.Object.keys x
                let length = keys.Count
                let mutable i = 0
                let mutable result = true
                while i < length && result do
                    let key = keys.[i]
                    i <- i + 1
                    let xValue = x?(key)
                    result <- is.function' xValue || obj.ReferenceEquals(xValue, y?(key))
                result
            else
                false

@nikhil-malviya
Copy link

Bump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants