Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

569 B
Raw Blame
/* Copyright 2026 Marimo. All rights reserved. */
import type { Atom } from "jotai";
import type { JotaiStore } from "./jotai";

export interface Observable<T> {
  get(): T;
  sub(callback: (value: T) => void): () => void;
}

/**
 * Create an observable from a Jotai atom.
 *
 * This is just a simpler read-only API that hides the Jotai store.
 */
export function createObservable<T>(
  value: Atom<T>,
  store: JotaiStore,
): Observable<T> {
  return {
    get: () => store.get(value),
    sub: (callback) => store.sub(value, () => callback(store.get(value))),
  };
}