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

Formik v3 Umbrella PR. #3231

Open
wants to merge 94 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
9f8765e
Started to reimplement subscriber.
johnrom Mar 8, 2021
4dc160b
Grab types from other PR, to simplify later.
johnrom Mar 9, 2021
ef66e38
Grab types from other PR, to simplify later.
johnrom Mar 9, 2021
b77d371
Merge branch 'johnrom/subscriber' of github.com:johnrom/formik into j…
johnrom Mar 9, 2021
3e6e20c
Set up dev environment and implement Field.
johnrom Mar 10, 2021
881d7e6
Memoize Formik API and make it rain optimized states.
johnrom Mar 11, 2021
b8e7fcd
Roll back unnecessary tsconfig change.
johnrom Mar 11, 2021
feaee0e
Fix Sign In App Page.
johnrom Mar 11, 2021
a5a2f47
Roll back unnecessary tsconfig change.
johnrom Mar 11, 2021
4037473
Wire up FormikConsumer.
johnrom Mar 11, 2021
e2c496c
Remove implementation details from deprecated comments.
johnrom Mar 11, 2021
a78459b
Don't expose internal useOptimizedSelector.
johnrom Mar 11, 2021
747ce07
Reduce maintenance surface by moving useOptimizedSelector into its ow…
johnrom Mar 15, 2021
9d10f82
Update use-optimized-selector
johnrom Mar 17, 2021
0d1cbfd
Move useFormikComputedState to api.useComputedState, useIsDirty and u…
johnrom Mar 17, 2021
0c18ebb
Accidental import change.
johnrom Mar 17, 2021
3ab46cd
Remove TSConfig path aliases during build.
johnrom Mar 17, 2021
5011168
If we're calling our own reducer, we don't need to useReducer! setSta…
johnrom Mar 18, 2021
a5f4643
Optimize field meta and computed state with shallow equals.
johnrom Mar 18, 2021
c9b9579
Move Computed State into normal state helpers so that FormikState = F…
jawnrom Mar 22, 2021
611432a
Merge pull request #3 from jawnstreams/johnrom/downstream
johnrom Mar 22, 2021
dc2e2fa
Clarify RenderState vs GetState. Fix Test.
johnrom Mar 22, 2021
0764e12
Fix tests with updated /app structure.
johnrom Mar 22, 2021
0079948
Remove unused helper components from app/
johnrom Mar 23, 2021
9c4cd01
Ignore TypeScript Build Errors during app/ build.
johnrom Mar 23, 2021
ba1fdb9
Add Changeset
johnrom Mar 23, 2021
e800bf8
Add Parse / Format to Subscriptions PR
johnrom Mar 24, 2021
c06dff8
Add changes from FieldArray over reducer-refs PR.
johnrom Mar 24, 2021
ba6f6c0
Add Field Array to App Index
johnrom Mar 24, 2021
70de3d1
Fix UseField type definition, add micro-hooks.
johnrom Mar 25, 2021
a8e5cbf
Separate FormikContext and FormikConfigContext
johnrom Mar 25, 2021
d718684
Add FormikConfig to connect, some type fixes.
johnrom Mar 25, 2021
df779d4
Merge branch 'johnrom/subscriber' into johnrom/use-optimized-selector
johnrom Mar 29, 2021
dfde363
Isolate subscriptions logic from useFormik to enforce correct use of …
johnrom Apr 12, 2021
46a6e17
Fix useFormikState documentation, fix getState stability.
johnrom Apr 12, 2021
ee43bb2
Get rid of unnecessary, autocompleted import.
johnrom Apr 12, 2021
7949c3d
React.SFC -> FC
johnrom Apr 12, 2021
94b8f22
Null coalesced errors and touched during resetForm.
johnrom Apr 12, 2021
2e75c75
Merge branch 'johnrom/subscriber' into johnrom/parse-format-subscript…
johnrom Apr 13, 2021
6355689
Merge branch 'johnrom/subscriber' into johnrom/field-array-subscriptions
johnrom Apr 13, 2021
2327d3b
Merge branch 'johnrom/parse-format-subscriptions' into johnrom/micro-…
johnrom Apr 13, 2021
39f7cfd
Merge branch 'johnrom/subscriber' into johnrom/use-optimized-selector
johnrom Apr 13, 2021
06b4bbb
Merge branch 'johnrom/subscriber' into johnrom/use-formik-config
johnrom Apr 13, 2021
00dac43
Tiny Field Fixes
johnrom Apr 13, 2021
f49f9e2
Update App/ to reflect config changes.
johnrom Apr 13, 2021
86eafd6
Fixed other instance of useFormik.
johnrom Apr 13, 2021
1821200
Move render optimization to FormikProvider.
johnrom Apr 14, 2021
ea22bab
Merge branch 'johnrom/field-array-subscriptions' into johnrom/v3
johnrom Apr 14, 2021
1060bfd
Merge branch 'johnrom/use-optimized-selector' into johnrom/v3
johnrom Apr 14, 2021
48c5771
Merge branch 'johnrom/micro-hooks-and-field-fixes' into johnrom/v3
johnrom Apr 14, 2021
c4e7a41
Merge branch 'johnrom/use-formik-config' into johnrom/v3
johnrom Apr 14, 2021
6d08add
Test packages.
johnrom Apr 14, 2021
f3bd303
fixed SetValues type, adding functional variant
johnrom Apr 16, 2021
a9216a0
Merge branch 'johnrom/subscriber' into johnrom/v3
johnrom Apr 16, 2021
4821467
Set package.json versions back to their originals, so changeset can u…
johnrom Jun 4, 2021
e0b804f
Merge remote-tracking branch 'upstream/master' into johnrom/v3
johnrom Jun 4, 2021
788c258
Merge remote-tracking branch 'upstream/master' into johnrom/v3-remerged
johnrom Jun 18, 2021
75c3c4d
Merge branch 'johnrom/v3-remerged' into johnrom/v3
johnrom Jun 18, 2021
f24e151
Re-merge these files because apparently they failed last time.
johnrom Jun 18, 2021
51502dc
Do basic radio / checkbox parsing, and put all the value parse logic …
johnrom Jul 8, 2021
58b538f
Merge pull request #7 from johnrom/johnrom/parsing-refactor
johnrom Jul 8, 2021
cb07eaa
Add publish package.json
johnrom Jul 8, 2021
4364adb
Batch updates instead of relying on state + effect.
johnrom Aug 12, 2021
ec88672
Correct attribution, document alternate-renderers and allow devs to o…
johnrom Aug 12, 2021
879fc05
Fix batch to reuse computed state. Add some comments to help explain …
johnrom Aug 12, 2021
baab2b8
Merge branch 'johnrom/v3' into johnrom/v3-publish
johnrom Aug 12, 2021
27aeccb
Publish refs4
johnrom Aug 12, 2021
4b76e2b
RN is not detecting .native suffix.
johnrom Aug 12, 2021
0620d41
Merge branch 'johnrom/v3' into johnrom/v3-publish
johnrom Aug 12, 2021
a173534
Change to use entrypoints instead of magic es modules.
johnrom Aug 12, 2021
41a8c4a
Manually built native files and removed prepublish action.
johnrom Aug 12, 2021
42f7a0e
Testing out manual native build
johnrom Aug 18, 2021
fa352ee
Merge branch 'master' into johnrom/v3-publish
johnrom Aug 20, 2021
56cdc92
Fix circular reference
johnrom Aug 20, 2021
5934815
Manually build a native version with tsdx, move it to index.native.js…
johnrom Aug 20, 2021
db6f834
Merge branch 'master' into johnrom/v3
jaredpalmer Aug 26, 2021
d5212de
Add full native app for testing using expo.
johnrom Aug 27, 2021
3e9dbb1
Configure expo for yarn workspaces.
johnrom Aug 27, 2021
ff266b5
Specific react and react-dom versions to fix workspace deduplication.
johnrom Aug 27, 2021
b4b889f
Native batch is working on Android, but not React-Native Web (Web is …
johnrom Aug 27, 2021
a133f2e
Fix handleChange type issue, remove package.json field for formik-nat…
johnrom Sep 12, 2021
d8e2923
Merge remote-tracking branch 'origin/johnrom/v3' into johnrom/native-…
johnrom Sep 12, 2021
4a7b3b5
Merge pull request #8 from johnrom/johnrom/native-tests
johnrom Sep 12, 2021
bbd0eaf
Fix circular dependencies.
johnrom Sep 12, 2021
2e8079c
Switch from npm to yarn scripts.
johnrom Sep 12, 2021
4548b41
Bump custom tsdx version to fix line endings.
johnrom Sep 12, 2021
66ca554
Updated yarn.lock.
johnrom Sep 12, 2021
1ad47cd
noclean3 for LF once and for all.
johnrom Sep 12, 2021
60801e7
Provide a default selector because it can be frustrating not to have …
johnrom Oct 8, 2021
c43ffc0
Add optional selector to useFormikSubscription.
johnrom Oct 8, 2021
3ba242a
add default Return type to formik.useState.
johnrom Oct 14, 2021
45e28c6
Add missing useIsValidating hook
dantman Oct 27, 2021
a38ded4
Merge pull request #9 from dantman/johnrom-v3-isvalidating
johnrom Oct 28, 2021
f899b89
Remove field from form-level validations. This isn't how it should be…
johnrom Apr 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/fifty-shrimps-leave.md
@@ -0,0 +1,10 @@
---
"formik-native": major
"formik": major
"app": major
---

Use FormikApi + FormikState Subscriptions

Switch underlying state implementation to use a subscription, and access that subscription via `useFormik().useState()` or its alias, `useFormikState()`.
useFormikContext() only contains a stable API as well as some config props which should eventually be moved to a separate FormikConfigContext for further optimization.
49 changes: 49 additions & 0 deletions .vscode/launch.json
@@ -0,0 +1,49 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Run NPM Dev",
"request": "launch",
"type": "node",
"runtimeArgs": [
"run",
"start:app"
],
"runtimeExecutable": "npm",
"cwd": "${workspaceFolder}",
"skipFiles": [
"<node_internals>/**"
]
},
{
"type": "node",
"name": "vscode-jest-tests",
"request": "launch",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/lerna",
"args": [
"run",
"test",
"--",
"--runInBand",
// when filtering, every package not matching will have no tests
"--passWithNoTests",
"--testTimeout=9999"
],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"protocol": "inspector",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true
},
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}/app"
}
]
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
@@ -1,3 +1,4 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"jest.pathToJest": "npm run test:vscode --",
}
6 changes: 6 additions & 0 deletions app-native/.expo-shared/assets.json
@@ -0,0 +1,6 @@
{
"e997a5256149a4b76e6bfd6cbf519c5e5a0f1d278a3d8fa1253022b03c90473b": true,
"af683c96e0ffd2cf81287651c9433fa44debc1220ca7cb431fe482747f34a505": true,
"12bb71342c6255bbf50437ec8f4441c083f47cdb74bd89160c15e4f43e52a1cb": true,
"40b842e832070c58deac6aa9e08fa459302ee3f9da492c7e77d93d2fbf4a56fd": true
}
13 changes: 13 additions & 0 deletions app-native/.gitignore
@@ -0,0 +1,13 @@
node_modules/
.expo/
npm-debug.*
*.jks
*.p8
*.p12
*.key
*.mobileprovision
*.orig.*
web-build/

# macOS
.DS_Store
23 changes: 23 additions & 0 deletions app-native/App.tsx
@@ -0,0 +1,23 @@
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { SafeAreaProvider } from 'react-native-safe-area-context';

import useCachedResources from './hooks/useCachedResources';
import useColorScheme from './hooks/useColorScheme';
import Navigation from './navigation';

export default function App() {
const isLoadingComplete = useCachedResources();
const colorScheme = useColorScheme();

if (!isLoadingComplete) {
return null;
} else {
return (
<SafeAreaProvider>
<Navigation colorScheme={colorScheme} />
<StatusBar />
</SafeAreaProvider>
);
}
}
13 changes: 13 additions & 0 deletions app-native/__generated__/AppEntry.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions app-native/app.json
@@ -0,0 +1,34 @@
{
"expo": {
"name": "app-native",
"slug": "app-native",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/images/icon.png",
"scheme": "myapp",
"userInterfaceStyle": "automatic",
"splash": {
"image": "./assets/images/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/images/adaptive-icon.png",
"backgroundColor": "#ffffff"
}
},
"web": {
"favicon": "./assets/images/favicon.png"
}
}
}
Binary file added app-native/assets/fonts/SpaceMono-Regular.ttf
Binary file not shown.
Binary file added app-native/assets/images/adaptive-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app-native/assets/images/favicon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app-native/assets/images/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app-native/assets/images/splash.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions app-native/babel.config.js
@@ -0,0 +1,7 @@
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
plugins: ['react-native-reanimated/plugin'],
};
};
80 changes: 80 additions & 0 deletions app-native/components/EditScreenInfo.tsx
@@ -0,0 +1,80 @@
import * as WebBrowser from 'expo-web-browser';
import React from 'react';
import { StyleSheet, TouchableOpacity } from 'react-native';

import Colors from '../constants/Colors';
import { MonoText } from './StyledText';
import { Text, View } from './Themed';

export default function EditScreenInfo({ path }: { path: string }) {
return (
<View>
<View style={styles.getStartedContainer}>
<Text
style={styles.getStartedText}
lightColor="rgba(0,0,0,0.8)"
darkColor="rgba(255,255,255,0.8)">
Open up the code for this screen:
</Text>

<View
style={[styles.codeHighlightContainer, styles.homeScreenFilename]}
darkColor="rgba(255,255,255,0.05)"
lightColor="rgba(0,0,0,0.05)">
<MonoText>{path}</MonoText>
</View>

<Text
style={styles.getStartedText}
lightColor="rgba(0,0,0,0.8)"
darkColor="rgba(255,255,255,0.8)">
Change any of the text, save the file, and your app will automatically update.
</Text>
</View>

<View style={styles.helpContainer}>
<TouchableOpacity onPress={handleHelpPress} style={styles.helpLink}>
<Text style={styles.helpLinkText} lightColor={Colors.light.tint}>
Tap here if your app doesn't automatically update after making changes
</Text>
</TouchableOpacity>
</View>
</View>
);
}

function handleHelpPress() {
WebBrowser.openBrowserAsync(
'https://docs.expo.io/get-started/create-a-new-app/#opening-the-app-on-your-phonetablet'
);
}

const styles = StyleSheet.create({
getStartedContainer: {
alignItems: 'center',
marginHorizontal: 50,
},
homeScreenFilename: {
marginVertical: 7,
},
codeHighlightContainer: {
borderRadius: 3,
paddingHorizontal: 4,
},
getStartedText: {
fontSize: 17,
lineHeight: 24,
textAlign: 'center',
},
helpContainer: {
marginTop: 15,
marginHorizontal: 20,
alignItems: 'center',
},
helpLink: {
paddingVertical: 15,
},
helpLinkText: {
textAlign: 'center',
},
});
7 changes: 7 additions & 0 deletions app-native/components/StyledText.tsx
@@ -0,0 +1,7 @@
import * as React from 'react';

import { Text, TextProps } from './Themed';

export function MonoText(props: TextProps) {
return <Text {...props} style={[props.style, { fontFamily: 'space-mono' }]} />;
}
13 changes: 13 additions & 0 deletions app-native/components/SubmitButton.tsx
@@ -0,0 +1,13 @@
import * as React from 'react';
import { Button } from 'react-native';
import { useSubmitButton } from 'formik-native';

interface SubmitButtonProps {
title?: string
}

export const SubmitButton = ({ title = "Submit" }) => {
const { onPress } = useSubmitButton();

return <Button title={title} onPress={onPress} />;
}
46 changes: 46 additions & 0 deletions app-native/components/Themed.tsx
@@ -0,0 +1,46 @@
/**
* Learn more about Light and Dark modes:
* https://docs.expo.io/guides/color-schemes/
*/

import * as React from 'react';
import { Text as DefaultText, View as DefaultView } from 'react-native';

import Colors from '../constants/Colors';
import useColorScheme from '../hooks/useColorScheme';

export function useThemeColor(
props: { light?: string; dark?: string },
colorName: keyof typeof Colors.light & keyof typeof Colors.dark
) {
const theme = useColorScheme();
const colorFromProps = props[theme];

if (colorFromProps) {
return colorFromProps;
} else {
return Colors[theme][colorName];
}
}

type ThemeProps = {
lightColor?: string;
darkColor?: string;
};

export type TextProps = ThemeProps & DefaultText['props'];
export type ViewProps = ThemeProps & DefaultView['props'];

export function Text(props: TextProps) {
const { style, lightColor, darkColor, ...otherProps } = props;
const color = useThemeColor({ light: lightColor, dark: darkColor }, 'text');

return <DefaultText style={[{ color }, style]} {...otherProps} />;
}

export function View(props: ViewProps) {
const { style, lightColor, darkColor, ...otherProps } = props;
const backgroundColor = useThemeColor({ light: lightColor, dark: darkColor }, 'background');

return <DefaultView style={[{ backgroundColor }, style]} {...otherProps} />;
}
10 changes: 10 additions & 0 deletions app-native/components/__tests__/StyledText-test.js
@@ -0,0 +1,10 @@
import * as React from 'react';
import renderer from 'react-test-renderer';

import { MonoText } from '../StyledText';

it(`renders correctly`, () => {
const tree = renderer.create(<MonoText>Snapshot test!</MonoText>).toJSON();

expect(tree).toMatchSnapshot();
});
19 changes: 19 additions & 0 deletions app-native/constants/Colors.ts
@@ -0,0 +1,19 @@
const tintColorLight = '#2f95dc';
const tintColorDark = '#fff';

export default {
light: {
text: '#000',
background: '#fff',
tint: tintColorLight,
tabIconDefault: '#ccc',
tabIconSelected: tintColorLight,
},
dark: {
text: '#fff',
background: '#000',
tint: tintColorDark,
tabIconDefault: '#ccc',
tabIconSelected: tintColorDark,
},
};
12 changes: 12 additions & 0 deletions app-native/constants/Layout.ts
@@ -0,0 +1,12 @@
import { Dimensions } from 'react-native';

const width = Dimensions.get('window').width;
const height = Dimensions.get('window').height;

export default {
window: {
width,
height,
},
isSmallDevice: width < 375,
};
33 changes: 33 additions & 0 deletions app-native/hooks/useCachedResources.ts
@@ -0,0 +1,33 @@
import { FontAwesome } from '@expo/vector-icons';
import * as Font from 'expo-font';
import * as SplashScreen from 'expo-splash-screen';
import * as React from 'react';

export default function useCachedResources() {
const [isLoadingComplete, setLoadingComplete] = React.useState(false);

// Load any resources or data that we need prior to rendering the app
React.useEffect(() => {
async function loadResourcesAndDataAsync() {
try {
SplashScreen.preventAutoHideAsync();

// Load fonts
await Font.loadAsync({
...FontAwesome.font,
'space-mono': require('../assets/fonts/SpaceMono-Regular.ttf'),
});
} catch (e) {
// We might want to provide this error information to an error reporting service
console.warn(e);
} finally {
setLoadingComplete(true);
SplashScreen.hideAsync();
}
}

loadResourcesAndDataAsync();
}, []);

return isLoadingComplete;
}