Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jotai-recoil-adapter: a community project for making life easier when migrating from Recoil to Jotai #2300

Open
clockelliptic opened this issue Jan 15, 2024 · 1 comment

Comments

@clockelliptic
Copy link

Hi everyone 👋,

TLDR; Check out clockelliptic/jotai-recoil-adapter. It's rough around the edges and could use community support, but has proven to be very useful so far. Please feel invited to contribute, fork, and copy as needed.

see it on NPM: https://www.npmjs.com/package/jotai-recoil-adapter

see also: #2288 #1495

🔍 What is jotai-recoil-adapter?
The jotai-recoil-adapter is intended to facilitate a less-painful transition from Recoil to Jotai. It provides an API compatible with Recoil while leveraging the simplicity and efficiency of Jotai under the hood. Our goal is to make it easier for teams reliant on Recoil to migrate to Jotai without having to overhaul their existing codebases.

🌟 Features Include:

  • An API mirroring key Recoil functionalities, such as atom, selector, useRecoilState, and more.

🤝 We Need Your Input!
This project is in its early stages, and community input is invaluable.

Current top priorities include:

  • expanded adapter APIs to support migration from Recoil's writable selectors (proxy selectors)
  • expanded adapter APIs for other Recoil APIs
  • test suite development
  • development of migration docs for Recoil APIs that aren't adaptable to Jotai

🔗 Get Involved:

  • Check out the repository: clockelliptic/jotai-recoil-adapter
  • Try it out in your projects and let us know your experience.
  • Report any issues or suggest enhancements on our issues page.
  • Feel free to fork the repo, submit PRs, or discuss potential features.
@clockelliptic
Copy link
Author

⚠️ Disclaimer: I do this in my spare time to help myself and others bootstrap their migration from Recoil to Jotai, please read the code and test your production applications thoroughly. This is a labor of love ❤️

see: https://github.com/clockelliptic/jotai-recoil-adapter


Update: v0.4.0

Adds support for atom and atomFamily effects:

export type EffectArgs<T> = {
  /* supported */
  onSet: (cb: (newVal: T, oldVal?: T) => void) => void;
  getPromise?: GetPromise;
  getLoadable?: GetLoadable;
  node?: AtomAdapter<T>;
  setSelf?: (value: T) => void;

  /* unsafe/messy to support */
  resetSelf?: UNSUPPORTED;

  /* does not apply to Jotai */
  storeID?: UNSUPPORTED;
  trigger?: UNSUPPORTED;
  getInfo_UNSTABLE?: UNSUPPORTED;
  parentStoreID_UNSTABLE?: UNSUPPORTED;
};

export type EffectFn<T> = (arg: EffectArgs<T>) => void;

Adds support for getLoadable and getPromise methods in atom effects and useRecoilCallback:

export type Loadable<T> =
  | { state: "hasValue"; contents: T }
  | { state: "hasError"; contents: Error }
  | { state: "loading" };

export type GetPromise = <T>(atom: AtomAdapter<T>) => Promise<T>;
export type GetLoadable = <T>(atom: AtomAdapter<T>) => Loadable<T>;

export type Snapshot = {
  getPromise: GetPromise;
  getLoadable: GetLoadable;
  retain: () => () => void; // does nothing, merely for drop-in convenience
};

Supported or partially supported APIs

import {
  /* standard Recoil APIs, fully or partially supported */
  RecoilRoot,
  atom,
  atomFamily,
  selector,
  selectorFamily,
  useRecoilCallback,
  useRecoilState,
  useRecoilValue,
  useSetRecoilState,
  useResetRecoilState,
  useRecoilBridgeAcrossReactRoots_UNSTABLE,

 /* interfaces, fully or partially implemented */
  Snapshot,
  Loadable,

  /* special adapters for compatibility */
  atomAsync,
  atomFamilyAsync,
  asyncSelector,
  asyncSelectorFamily,
  selectorDefault
} from 'jotai-recoil-adapter';

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

No branches or pull requests

1 participant