Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 1774

Recursive references in library binding function body?

$
0
0

I’m working with Preact’s signals in ReScript and I’m implementing a lightweight Finite State Machine using variants. I’m trying to implement a transitionSignal so that components can subscribe to transitions to trigger effects or react to various state changes.


  let transitionSignal: Signal.t<transition> = Signal.computed(() => {
    let action = actionSignal->Signal.get
		let nextState = stateSignal->Signal.get
    let {nextState: prevState} = transitionSignal->Signal.peek

    {next: nextState, prev: prevState, action}
  })

The problem is that rescript does not like let {nextState: prevState} = transitionSignal->Signal.peek due to it not being defined yet. I’ve tried adding let rec ... but that doesn’t work either as the compiler throws a "This kind of expression is not allowed as right-hand side of let rec" error.

Any suggestions for what can be done to make that work? I could have a private signal for the last state change but that is suboptimal.


Viewing all articles
Browse latest Browse all 1774

Trending Articles