Skip to content

Remove dependency on Fable.Extras #13

@JaggerJo

Description

@JaggerJo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions