Skip to content

Conversation

@pearmini
Copy link
Collaborator

@pearmini pearmini commented Sep 20, 2025

Ref. #190

Here is a basic example for recho.state(value):

const [a, setA] = recho.state(0);

setTimeout(() => {
  setA((a) => a + 1);
}, 1000);

echo(a);

This feature is useful for interactive data structure visualization.

class Stack {
  pop() {}
  clone() {}
}

const [stack, setStack] = recho.state(new Stack());

echo(stack.values.join(",")):

recho.button("pop", () => {
  stack.pop();
  setStack(stack.clone());
});

@pearmini pearmini marked this pull request as draft September 20, 2025 03:27
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Sep 20, 2025

Deploying recho with  Cloudflare Pages  Cloudflare Pages

Latest commit: dcd1c0b
Status: ✅  Deploy successful!
Preview URL: https://fb16d009.recho.pages.dev
Branch Preview URL: https://mutable.recho.pages.dev

View logs

@pearmini pearmini changed the title Add mutable Add __mutator__ Sep 20, 2025
@pearmini pearmini requested a review from chengluyu September 20, 2025 14:19
@pearmini pearmini force-pushed the main branch 9 times, most recently from 3f305c5 to 9edb43c Compare October 6, 2025 13:46
@pearmini pearmini force-pushed the main branch 3 times, most recently from 5c9c667 to 5dbb7e0 Compare October 20, 2025 17:13
@vercel
Copy link

vercel bot commented Nov 8, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
recho-notebook Ready Ready Preview Comment Nov 8, 2025 9:19pm

@pearmini pearmini changed the title Add __mutator__ Add recho.state(value) Nov 8, 2025
@pearmini pearmini marked this pull request as ready for review November 8, 2025 21:16
@pearmini pearmini requested a review from Copilot November 8, 2025 21:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new state function to the standard library that provides React-like state management capabilities. The implementation is derived from Observable Notebook Kit's mutable and observe utilities.

  • Implements a state() function that returns a tuple of [state, setState, getState] for reactive state management
  • Adds the observe generator utility to support reactive value updates
  • Includes test coverage for the new functionality

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
runtime/stdlib/state.js Implements the state() function and internal Mutable helper using the observe generator
runtime/stdlib/observe.js Adds async generator for reactive value observation with initialization and disposal lifecycle
runtime/stdlib/index.js Exports the new state function from the stdlib module
test/stdlib.spec.js Adds test assertion to verify state is exported from stdlib
test/js/mutable.js Adds test case demonstrating state usage with setter callbacks
test/js/index.js Exports the new mutable test case

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Successfully merging this pull request may close these issues.

2 participants