Skip to content

Commit

Permalink
feat(jotai): Added atomWithWebStorage and atomWithBroadcast atom …
Browse files Browse the repository at this point in the history
…creators
  • Loading branch information
sullivanpj committed Dec 17, 2023
1 parent 03aa93d commit 4124c6c
Show file tree
Hide file tree
Showing 19 changed files with 549 additions and 17 deletions.
38 changes: 36 additions & 2 deletions docs/api-reports/packages/jotai/api-report.md
Expand Up @@ -3,28 +3,62 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { AsyncStorage } from "jotai/vanilla/utils/atomWithStorage";
import { AsyncStringStorage } from "jotai/vanilla/utils/atomWithStorage";
import { Atom } from "jotai/vanilla";
import type { Getter } from "jotai/vanilla";
import { PrimitiveAtom } from "jotai/vanilla";
import { SetStateAction } from "react";
import type { Setter } from "jotai/vanilla";
import { SyncStorage } from "jotai/vanilla/utils/atomWithStorage";
import { SyncStringStorage } from "jotai/vanilla/utils/atomWithStorage";
import { useAtomValue } from "jotai/react";
import { WritableAtom } from "jotai/vanilla";
import { WritableAtom as WritableAtom_2 } from "jotai";

// @public (undocumented)
// @public
function atomEffect(
effectFn: (get: Getter, set: Setter) => void | CleanupFn
): Atom<void>;
export { atomEffect };
export { atomEffect as atomEffect_alias_1 };
export { atomEffect as atomEffect_alias_2 };

// @public (undocumented)
// @public
function atomWithBroadcast<TValue>(
key: string,
initialValue: TValue
): WritableAtom<TValue, [TValue], void>;
export { atomWithBroadcast };
export { atomWithBroadcast as atomWithBroadcast_alias_1 };
export { atomWithBroadcast as atomWithBroadcast_alias_2 };

// @public
const atomWithPending: <Value>() => PrimitiveAtom<Value> & {
init: Value;
};
export { atomWithPending };
export { atomWithPending as atomWithPending_alias_1 };
export { atomWithPending as atomWithPending_alias_2 };

// @public
function atomWithWebStorage<TValue = unknown>(
key: string,
initialValue: TValue,
webStorage?: SyncStorage<TValue> | AsyncStorage<TValue>
): WritableAtom_2<TValue, [SetStateAction<TValue>], void>;
export { atomWithWebStorage };
export { atomWithWebStorage as atomWithWebStorage_alias_1 };
export { atomWithWebStorage as atomWithWebStorage_alias_2 };

// @public (undocumented)
function createWebStorage<TValue>(
getStringStorage: () => AsyncStringStorage | SyncStringStorage | undefined
): AsyncStorage<TValue> | SyncStorage<TValue>;
export { createWebStorage };
export { createWebStorage as createWebStorage_alias_1 };
export { createWebStorage as createWebStorage_alias_2 };

// @public
const setAtomDebugLabel: (atom: Atom<unknown>, label: string) => void;
export { setAtomDebugLabel };
Expand Down
294 changes: 292 additions & 2 deletions docs/api-reports/packages/jotai/documents-model.api.json
Expand Up @@ -175,7 +175,7 @@
{
"kind": "Function",
"canonicalReference": "@storm-stack/jotai!atomEffect:function(1)",
"docComment": "",
"docComment": "/**\n * Creates an atom that runs an effect function when mounted and unmounts.\n *\n * @param effectFn - The effect function to run\n *\n * @returns An atom that runs an effect function when mounted and unmounts.\n */\n",
"excerptTokens": [
{
"kind": "Content",
Expand Down Expand Up @@ -240,10 +240,84 @@
],
"name": "atomEffect"
},
{
"kind": "Function",
"canonicalReference": "@storm-stack/jotai!atomWithBroadcast:function(1)",
"docComment": "/**\n * Creates an atom that broadcasts its value to other tabs/windows using the BroadcastChannel API.\n *\n * @param key - The key to use for the BroadcastChannel\n *\n * @param initialValue - The initial value of the atom\n *\n * @returns An atom that broadcasts its value to other tabs/windows using the BroadcastChannel API.\n */\n",
"excerptTokens": [
{
"kind": "Content",
"text": "export declare function atomWithBroadcast<TValue>(key: "
},
{
"kind": "Content",
"text": "string"
},
{
"kind": "Content",
"text": ", initialValue: "
},
{
"kind": "Content",
"text": "TValue"
},
{
"kind": "Content",
"text": "): "
},
{
"kind": "Content",
"text": "import(\"jotai/vanilla\").WritableAtom<TValue, [TValue], void>"
},
{
"kind": "Content",
"text": ";"
}
],
"fileUrlPath": "packages/jotai/src/atoms/atom-with-broadcast.ts",
"returnTypeTokenRange": {
"startIndex": 5,
"endIndex": 6
},
"releaseTag": "Public",
"overloadIndex": 1,
"parameters": [
{
"parameterName": "key",
"parameterTypeTokenRange": {
"startIndex": 1,
"endIndex": 2
},
"isOptional": false
},
{
"parameterName": "initialValue",
"parameterTypeTokenRange": {
"startIndex": 3,
"endIndex": 4
},
"isOptional": false
}
],
"typeParameters": [
{
"typeParameterName": "TValue",
"constraintTokenRange": {
"startIndex": 0,
"endIndex": 0
},
"defaultTypeTokenRange": {
"startIndex": 0,
"endIndex": 0
}
}
],
"name": "atomWithBroadcast"
},
{
"kind": "Variable",
"canonicalReference": "@storm-stack/jotai!atomWithPending:var",
"docComment": "",
"docComment": "/**\n * Creates an atom that always returns a pending promise.\n *\n * @returns An atom that always returns a pending promise.\n */\n",
"excerptTokens": [
{
"kind": "Content",
Expand All @@ -263,6 +337,222 @@
"endIndex": 2
}
},
{
"kind": "Function",
"canonicalReference": "@storm-stack/jotai!atomWithWebStorage:function(1)",
"docComment": "/**\n * Creates an atom that persists its state in external storage and sends a broadcast message to other tabs/windows when the state changes.\n *\n * @param key - The key to use for the storage\n *\n * @param initialValue - The initial value of the atom\n *\n * @param webStorage - The storage to use\n *\n * @returns An atom that persists its state in external storage and sends a broadcast message to other tabs/windows when the state changes.\n */\n",
"excerptTokens": [
{
"kind": "Content",
"text": "export declare function atomWithWebStorage<TValue = "
},
{
"kind": "Content",
"text": "unknown"
},
{
"kind": "Content",
"text": ">(key: "
},
{
"kind": "Content",
"text": "string"
},
{
"kind": "Content",
"text": ", initialValue: "
},
{
"kind": "Content",
"text": "TValue"
},
{
"kind": "Content",
"text": ", webStorage?: "
},
{
"kind": "Reference",
"text": "SyncStorage",
"canonicalReference": "!unknown"
},
{
"kind": "Content",
"text": "<TValue> | "
},
{
"kind": "Reference",
"text": "AsyncStorage",
"canonicalReference": "!unknown"
},
{
"kind": "Content",
"text": "<TValue>"
},
{
"kind": "Content",
"text": "): "
},
{
"kind": "Reference",
"text": "WritableAtom",
"canonicalReference": "!unknown"
},
{
"kind": "Content",
"text": "<TValue, ["
},
{
"kind": "Reference",
"text": "SetStateAction",
"canonicalReference": "@types/react!React.SetStateAction:type"
},
{
"kind": "Content",
"text": "<TValue>], void>"
},
{
"kind": "Content",
"text": ";"
}
],
"fileUrlPath": "packages/jotai/src/atoms/atom-with-web-storage.ts",
"returnTypeTokenRange": {
"startIndex": 12,
"endIndex": 16
},
"releaseTag": "Public",
"overloadIndex": 1,
"parameters": [
{
"parameterName": "key",
"parameterTypeTokenRange": {
"startIndex": 3,
"endIndex": 4
},
"isOptional": false
},
{
"parameterName": "initialValue",
"parameterTypeTokenRange": {
"startIndex": 5,
"endIndex": 6
},
"isOptional": false
},
{
"parameterName": "webStorage",
"parameterTypeTokenRange": {
"startIndex": 7,
"endIndex": 11
},
"isOptional": true
}
],
"typeParameters": [
{
"typeParameterName": "TValue",
"constraintTokenRange": {
"startIndex": 0,
"endIndex": 0
},
"defaultTypeTokenRange": {
"startIndex": 1,
"endIndex": 2
}
}
],
"name": "atomWithWebStorage"
},
{
"kind": "Function",
"canonicalReference": "@storm-stack/jotai!createWebStorage:function(1)",
"docComment": "",
"excerptTokens": [
{
"kind": "Content",
"text": "export declare function createWebStorage<TValue>(getStringStorage: "
},
{
"kind": "Content",
"text": "() => "
},
{
"kind": "Reference",
"text": "AsyncStringStorage",
"canonicalReference": "!unknown"
},
{
"kind": "Content",
"text": " | "
},
{
"kind": "Reference",
"text": "SyncStringStorage",
"canonicalReference": "!unknown"
},
{
"kind": "Content",
"text": " | undefined"
},
{
"kind": "Content",
"text": "): "
},
{
"kind": "Reference",
"text": "AsyncStorage",
"canonicalReference": "!unknown"
},
{
"kind": "Content",
"text": "<TValue> | "
},
{
"kind": "Reference",
"text": "SyncStorage",
"canonicalReference": "!unknown"
},
{
"kind": "Content",
"text": "<TValue>"
},
{
"kind": "Content",
"text": ";"
}
],
"fileUrlPath": "packages/jotai/src/utilities/create-web-storage.ts",
"returnTypeTokenRange": {
"startIndex": 7,
"endIndex": 11
},
"releaseTag": "Public",
"overloadIndex": 1,
"parameters": [
{
"parameterName": "getStringStorage",
"parameterTypeTokenRange": {
"startIndex": 1,
"endIndex": 6
},
"isOptional": false
}
],
"typeParameters": [
{
"typeParameterName": "TValue",
"constraintTokenRange": {
"startIndex": 0,
"endIndex": 0
},
"defaultTypeTokenRange": {
"startIndex": 0,
"endIndex": 0
}
}
],
"name": "createWebStorage"
},
{
"kind": "Variable",
"canonicalReference": "@storm-stack/jotai!setAtomDebugLabel:var",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/README.md
Expand Up @@ -16,7 +16,7 @@ This package is part of the <b>⚡storm-stack</b> monorepo. The storm-stack pack

<h3 align="center">💻 Visit <a href="https://stormsoftware.org" target="_blank">stormsoftware.org</a> to stay up to date with this developer</h3><br />

[![Version](https://img.shields.io/badge/version-1.0.12-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;
[![Version](https://img.shields.io/badge/version-1.0.13-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;
[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with docusaurus](https://img.shields.io/badge/documented_with-docusaurus-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://docusaurus.io/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-ops/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)

<h3 align="center" bold="true">⚠️ <b>Attention</b> ⚠️ This repository, and the apps, libraries, and tools contained within, is still in it's initial development phase. As a result, bugs and issues are expected with it's usage. When the main development phase completes, a proper release will be performed, the packages will be availible through NPM (and other distributions), and this message will be removed. However, in the meantime, please feel free to report any issues you may come across.</h3><br />
Expand Down

0 comments on commit 4124c6c

Please sign in to comment.