shmew / feliz.recoil Goto Github PK
View Code? Open in Web Editor NEWFable bindings in Feliz style for Facebook's experimental state management library recoil.
Home Page: https://shmew.github.io/Feliz.Recoil/
License: MIT License
Fable bindings in Feliz style for Facebook's experimental state management library recoil.
Home Page: https://shmew.github.io/Feliz.Recoil/
License: MIT License
I would like to trigger an action (perform a side effect) every time a value of a particular atom changes but can not find the appropriate hook in the API. Specifically, I would like to update the URL parameters based on the value of the atom.
Ideally, this could be possible by specifying an async callback in the definition of an atom.
Looking at the Recoil spec I could not figure out if this is at all possible with Recoil.
Currently, I am seeing elmish is based on a simple elmish loop without commands. It would be nice if full elmish with commands are supported.
Compalition fails because of issues with Fable.Extras
dotnet add package Feliz.Recoil
open Feliz.Recoil
and let textState = Recoil.atom("Basic/textState", "Hello world!")
to the App.fs file.dotnet fable src
The build should not fail.
./src/Main.fs(6,1): (6,16) warning FSHARP: This construct is deprecated. ReactDOM.render is obsolete since React v18. Please use the ReactDOM.createRoot API instead (code 44) ./src/Main.fs(6,1): (10,2) warning FSHARP: This construct is deprecated. ReactDOM.render is obsolete since React v18. Please use the ReactDOM.createRoot API instead (code 44) ./src/fable_modules/Fable.Extras.0.2.2/Extras.fs(149,17): (149,19) error FSHARP: This type parameter has been used in a way that constrains it to always be ''a option' (code 663) ./src/fable_modules/Fable.Extras.0.2.2/Extras.fs(149,17): (149,19) error FSHARP: This code is less generic than required by its annotations because the explicit type variable 'V' could not be generalized. It was constrained to be ''a option'. (code 660) ./src/fable_modules/Fable.Extras.0.2.2/Extras.fs(210,25): (210,28) error FSHARP: The generic member 'set' has been used at a non-uniform instantiation prior to this program point. Consider reordering the members so this member occurs first. Alternatively, specify the full type of the member explicitly, including argument types, return type and any additional generic parameters and constraints. (code 1198) ./src/fable_modules/Fable.Extras.0.2.2/Extras.fs(210,75): (210,80) error FSHARP: Type mismatch. Expecting a ''a option option' but given a ''a option' The types ''a' and ''a option' cannot be unified. (code 1) ./src/fable_modules/Fable.Extras.0.2.2/Extras.fs(266,21): (266,23) error FSHARP: This type parameter has been used in a way that constrains it to always be ''a option' (code 663) ./src/fable_modules/Fable.Extras.0.2.2/Extras.fs(266,21): (266,23) error FSHARP: This code is less generic than required by its annotations because the explicit type variable 'V' could not be generalized. It was constrained to be ''a option'. (code 660) ./src/fable_modules/Fable.Extras.0.2.2/Extras.fs(293,25): (293,28) error FSHARP: The generic member 'set' has been used at a non-uniform instantiation prior to this program point. Consider reordering the members so this member occurs first. Alternatively, specify the full type of the member explicitly, including argument types, return type and any additional generic parameters and constraints. (code 1198) ./src/fable_modules/Fable.Extras.0.2.2/Extras.fs(293,75): (293,80) error FSHARP: Type mismatch. Expecting a ''a option option' but given a ''a option' The types ''a' and ''a option' cannot be unified. (code 1) ./src/fable_modules/Fable.Extras.0.2.2/Extras.fs(984,28): (984,50) error FSHARP: A unique overload for method 'Date' could not be determined based on type information prior to this program point. A type annotation may be needed.Known type of argument: int
Candidates:
Known type of argument: int
Candidates:
Fable.Extras does not compile with the latest fable version.
Only a few functions from Fable.Extras are actually used. I'd suggest to get rid of the dependency.
Updating Fable.Extras to work with the latest Fable version.
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
When I try to use like this:
let test = Recoil.atom("test", promise { return 123})
React.functionComponent (fun () ->
let v = Recoil.useValue(Tool.test)
Browser.Dom.console.error v
Html.text "test"
)
I will get error: Uncaught ReferenceError: selector is not defined
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.