diff --git a/example/package.json b/example/package.json index 30b780c..e22a589 100644 --- a/example/package.json +++ b/example/package.json @@ -11,6 +11,7 @@ "dependencies": { "@react-native-community/blur": "^3.6.0", "@react-native-community/cameraroll": "^4.0.2", + "pipestate": "^1.0.2", "react": "16.13.1", "react-native": "0.63.4", "react-native-gesture-handler": "^1.10.1", diff --git a/example/src/state/atoms.ts b/example/src/state/atoms.ts new file mode 100644 index 0000000..793d5e5 --- /dev/null +++ b/example/src/state/atoms.ts @@ -0,0 +1,11 @@ +import { atom } from 'pipestate'; + +interface FormatSettings { + fps: number; +} + +export const FormatSettingsAtom = atom({ + default: { + fps: 50, + }, +}); diff --git a/example/src/state/selectors.ts b/example/src/state/selectors.ts new file mode 100644 index 0000000..49ef850 --- /dev/null +++ b/example/src/state/selectors.ts @@ -0,0 +1,13 @@ +import { selector } from 'pipestate'; +import { FormatSettingsAtom } from './atoms'; + +export const FpsSelector = selector({ + get: ({ get }) => { + return get(FormatSettingsAtom).fps; + }, + set: ({ set, get }, newFps) => { + const formatSettings = get(FormatSettingsAtom); + set(FormatSettingsAtom, { ...formatSettings, fps: newFps }); + }, + dependencies: [FormatSettingsAtom], +});