├── .editorconfig
├── .eslintignore
├── .gitattributes
├── .github
├── FUNDING.yml
└── workflows
│ ├── build.yml
│ ├── publish.yml
│ └── review.yml
├── .gitignore
├── .npmrc
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── assets
└── logo.png
├── babel.config.js
├── example
├── .storybook
│ ├── main.js
│ └── preview.js
├── app.json
├── babel.config.js
├── index.js
├── metro.config.js
├── package.json
├── src
│ ├── App.tsx
│ ├── Components
│ │ ├── HomePage.tsx
│ │ └── ToggleButton.tsx
│ ├── assets
│ │ └── logo.png
│ ├── color
│ │ └── color.tsx
│ ├── hooks
│ │ └── useDarkMode.tsx
│ └── stories
│ │ ├── API.stories.mdx
│ │ ├── Counter.tsx
│ │ ├── CounterWithInitialValue.stories.tsx
│ │ ├── CounterWithoutInitialValue.stories.tsx
│ │ ├── GettingStarted.stories.mdx
│ │ ├── Performance.stories.mdx
│ │ └── ToggleExample.tsx
├── webpack.config.js
└── yarn.lock
├── jest.config.js
├── package.json
├── src
├── __tests__
│ └── index.test.tsx
└── index.tsx
├── tsconfig.json
└── yarn.lock
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # editorconfig.org
4 |
5 | root = true
6 |
7 | [*]
8 |
9 | indent_style = space
10 | indent_size = 2
11 |
12 | end_of_line = lf
13 | charset = utf-8
14 | trim_trailing_whitespace = true
15 | insert_final_newline = true
16 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | lib
2 | node_modules
3 | storybook-static
4 | web-build
5 | coverage
6 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.pbxproj -text
2 | # specific for windows script files
3 | *.bat text eol=crlf
4 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | custom: [buymeacoffee.com/daniakash]
2 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: build
2 | on:
3 | push:
4 | branches:
5 | - master
6 | tags:
7 | - '!*'
8 | paths:
9 | - example/*
10 | - src/*
11 | - test/*
12 | - __tests__/*
13 | - '*.json'
14 | - yarn.lock
15 | - .github/**/*.yml
16 |
17 | jobs:
18 | lint:
19 | name: lint
20 | runs-on: ubuntu-latest
21 | steps:
22 | - uses: actions/checkout@master
23 | - uses: actions/setup-node@master
24 | with:
25 | node-version: 12.x
26 | - run: npx yarn bootstrap
27 | - run: npx yarn typescript
28 | - run: npx yarn lint
29 |
30 | test:
31 | strategy:
32 | matrix:
33 | platform: [ubuntu-latest, macOS-latest]
34 | node: ['12.x']
35 | name: test/node ${{ matrix.node }}/${{ matrix.platform }}
36 | runs-on: ${{ matrix.platform }}
37 | steps:
38 | - uses: actions/checkout@master
39 | - uses: actions/setup-node@master
40 | with:
41 | node-version: ${{ matrix.node }}
42 | - run: npx yarn bootstrap
43 | - run: npx yarn test
44 |
45 | coverage:
46 | needs: [test, lint]
47 | name: coverage
48 | runs-on: ubuntu-latest
49 | steps:
50 | - uses: actions/checkout@master
51 | - uses: actions/setup-node@master
52 | with:
53 | node-version: 12.x
54 | - run: npx yarn bootstrap
55 | - uses: paambaati/codeclimate-action@v2.5.3
56 | env:
57 | CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
58 | with:
59 | coverageCommand: npx yarn test --coverage
60 | debug: true
61 |
62 | publish:
63 | needs: [test, lint]
64 | name: Publish example app to Expo 🚀
65 | runs-on: ubuntu-latest
66 | steps:
67 | - uses: actions/checkout@v2
68 | - uses: actions/setup-node@v1
69 | with:
70 | node-version: 12.x
71 | - uses: expo/expo-github-action@v5
72 | with:
73 | expo-version: 3.x
74 | expo-username: ${{ secrets.EXPO_CLI_USERNAME }}
75 | expo-password: ${{ secrets.EXPO_CLI_PASSWORD }}
76 | - run: npx yarn bootstrap
77 | - working-directory: example
78 | run: expo publish
79 |
80 | chromatic:
81 | needs: [test, lint]
82 | name: Publish storybook to chromatic 🧪
83 | runs-on: ubuntu-latest
84 | steps:
85 | - uses: actions/checkout@v2
86 | - uses: actions/setup-node@v1
87 | with:
88 | node-version: 12.x
89 | - run: npx yarn bootstrap
90 | - run: npx yarn chromatic
91 | working-directory: example
92 | env:
93 | CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
94 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: publish
2 | on:
3 | release:
4 | types: [published]
5 |
6 | jobs:
7 | lint:
8 | name: lint
9 | runs-on: ubuntu-latest
10 | steps:
11 | - uses: actions/checkout@master
12 | - uses: actions/setup-node@master
13 | with:
14 | node-version: 12.x
15 | - run: npx yarn bootstrap
16 | - run: npx yarn typescript
17 | - run: npx yarn lint
18 |
19 | test:
20 | strategy:
21 | matrix:
22 | platform: [ubuntu-latest, macOS-latest]
23 | node: ['12.x']
24 | name: test/node ${{ matrix.node }}/${{ matrix.platform }}
25 | runs-on: ${{ matrix.platform }}
26 | steps:
27 | - uses: actions/checkout@master
28 | - uses: actions/setup-node@master
29 | with:
30 | node-version: ${{ matrix.node }}
31 | - run: npx yarn bootstrap
32 | - run: npx yarn test
33 |
34 | publish:
35 | needs: [test, lint]
36 | name: Publish to npm 🚢📦
37 | runs-on: ubuntu-latest
38 | steps:
39 | - uses: actions/checkout@master
40 | - uses: actions/setup-node@master
41 | with:
42 | node-version: 12.x
43 | - run: npx yarn bootstrap
44 | - uses: JS-DevTools/npm-publish@v1
45 | with:
46 | token: ${{ secrets.NPM_TOKEN }}
47 |
--------------------------------------------------------------------------------
/.github/workflows/review.yml:
--------------------------------------------------------------------------------
1 | name: review
2 | on: pull_request
3 |
4 | jobs:
5 | lint:
6 | name: lint
7 | runs-on: ubuntu-latest
8 | steps:
9 | - uses: actions/checkout@master
10 | - uses: actions/setup-node@master
11 | with:
12 | node-version: 12.x
13 | - run: npx yarn bootstrap
14 | - run: npx yarn typescript
15 | - run: npx yarn lint
16 |
17 | test:
18 | strategy:
19 | matrix:
20 | platform: [ubuntu-latest, macOS-latest]
21 | node: ['12.x']
22 | name: test/node ${{ matrix.node }}/${{ matrix.platform }}
23 | runs-on: ${{ matrix.platform }}
24 | steps:
25 | - uses: actions/checkout@master
26 | - uses: actions/setup-node@master
27 | with:
28 | node-version: ${{ matrix.node }}
29 | - run: npx yarn bootstrap
30 | - run: npx yarn test
31 |
32 | coverage:
33 | needs: [test, lint]
34 | name: coverage
35 | runs-on: ubuntu-latest
36 | steps:
37 | - uses: actions/checkout@master
38 | - uses: actions/setup-node@master
39 | with:
40 | node-version: 12.x
41 | - run: npx yarn bootstrap
42 | - run: npx yarn test --coverage
43 | - uses: romeovs/lcov-reporter-action@v0.2.16
44 | with:
45 | github-token: ${{ secrets.GITHUB_TOKEN }}
46 |
47 | chromatic:
48 | needs: [test, lint]
49 | name: Publish storybook to chromatic 🧪
50 | runs-on: ubuntu-latest
51 | steps:
52 | - uses: actions/checkout@v2
53 | - uses: actions/setup-node@v1
54 | with:
55 | node-version: 12.x
56 | - run: npx yarn bootstrap
57 | - run: npx yarn chromatic
58 | working-directory: example
59 | env:
60 | CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
61 |
62 | expo-publish:
63 | needs: [test, lint]
64 | name: Publish to Expo 🚀
65 | runs-on: ubuntu-latest
66 | steps:
67 | - uses: actions/checkout@v2
68 | - uses: actions/setup-node@v1
69 | with:
70 | node-version: 12.x
71 | - uses: expo/expo-github-action@v5
72 | with:
73 | expo-version: 3.x
74 | expo-username: ${{ secrets.EXPO_CLI_USERNAME }}
75 | expo-password: ${{ secrets.EXPO_CLI_PASSWORD }}
76 | - run: npx yarn bootstrap
77 | - run: expo publish --release-channel=pr-${{ github.event.number }}
78 | working-directory: example
79 | - uses: unsplash/comment-on-pr@master
80 | env:
81 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82 | with:
83 | msg: App is ready for review, you can [see it here](https://expo.io/@daniakash/rex-state-example?release-channel=pr-${{ github.event.number }}).
84 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # logs
2 | *.log
3 |
4 | # coverage
5 | coverage
6 |
7 | # OSX
8 | #
9 | .DS_Store
10 |
11 | # storybook
12 | storybook-static
13 |
14 | # XDE
15 | .expo/
16 | web-build
17 |
18 | # VSCode
19 | .vscode/
20 | jsconfig.json
21 |
22 | # Xcode
23 | #
24 | build/
25 | *.pbxuser
26 | !default.pbxuser
27 | *.mode1v3
28 | !default.mode1v3
29 | *.mode2v3
30 | !default.mode2v3
31 | *.perspectivev3
32 | !default.perspectivev3
33 | xcuserdata
34 | *.xccheckout
35 | *.moved-aside
36 | DerivedData
37 | *.hmap
38 | *.ipa
39 | *.xcuserstate
40 | project.xcworkspace
41 |
42 | # Android/IJ
43 | #
44 | .idea
45 | .gradle
46 | local.properties
47 | android.iml
48 |
49 | # Cocoapods
50 | #
51 | example/ios/Pods
52 |
53 | # node.js
54 | #
55 | node_modules/
56 | npm-debug.log
57 | yarn-debug.log
58 | yarn-error.log
59 |
60 | # BUCK
61 | buck-out/
62 | \.buckd/
63 | android/app/libs
64 | android/keystores/debug.keystore
65 |
66 | # Expo
67 | .expo/*
68 |
69 | # generated by bob
70 | lib/
71 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | save-exact=true
2 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project.
4 |
5 | ## Development workflow
6 |
7 | To get started with the project, run `yarn bootstrap` in the root directory to install the required dependencies for each package:
8 |
9 | ```sh
10 | yarn bootstrap
11 | ```
12 |
13 | While developing, you can run the [example app](/example/) to test your changes.
14 |
15 | To start the packager:
16 |
17 | ```sh
18 | yarn example start
19 | ```
20 |
21 | To run the example app on Android:
22 |
23 | ```sh
24 | yarn example android
25 | ```
26 |
27 | To run the example app on iOS:
28 |
29 | ```sh
30 | yarn example ios
31 | ```
32 |
33 | Make sure your code passes TypeScript and ESLint. Run the following to verify:
34 |
35 | ```sh
36 | yarn typescript
37 | yarn lint
38 | ```
39 |
40 | To fix formatting errors, run the following:
41 |
42 | ```sh
43 | yarn lint --fix
44 | ```
45 |
46 | Remember to add tests for your change if possible. Run the unit tests by:
47 |
48 | ```sh
49 | yarn test
50 | ```
51 |
52 | To edit the Objective-C files, open `example/ios/RexStateExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > rex-state`.
53 |
54 | To edit the Kotlin files, open `example/android` in Android studio and find the source files at `rexstate` under `Android`.
55 |
56 | ### Commit message convention
57 |
58 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages:
59 |
60 | - `fix`: bug fixes, e.g. fix crash due to deprecated method.
61 | - `feat`: new features, e.g. add new method to the module.
62 | - `refactor`: code refactor, e.g. migrate from class components to hooks.
63 | - `docs`: changes into documentation, e.g. add usage example for the module..
64 | - `test`: adding or updating tests, eg add integration tests using detox.
65 | - `chore`: tooling changes, e.g. change CI config.
66 |
67 | Our pre-commit hooks verify that your commit message matches this format when committing.
68 |
69 | ### Linting and tests
70 |
71 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/)
72 |
73 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing.
74 |
75 | Our pre-commit hooks verify that the linter and tests pass when committing.
76 |
77 | ### Scripts
78 |
79 | The `package.json` file contains various scripts for common tasks:
80 |
81 | - `yarn bootstrap`: setup project by installing all dependencies and pods.
82 | - `yarn typescript`: type-check files with TypeScript.
83 | - `yarn lint`: lint files with ESLint.
84 | - `yarn test`: run unit tests with Jest.
85 | - `yarn example start`: start the Metro server for the example app.
86 | - `yarn example android`: run the example app on Android.
87 | - `yarn example ios`: run the example app on iOS.
88 |
89 | ### Sending a pull request
90 |
91 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github).
92 |
93 | When you're sending a pull request:
94 |
95 | - Prefer small pull requests focused on one change.
96 | - Verify that linters and tests are passing.
97 | - Review the documentation to make sure it looks good.
98 | - Follow the pull request template when opening a pull request.
99 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue.
100 |
101 | ## Code of Conduct
102 |
103 | ### Our Pledge
104 |
105 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
106 |
107 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
108 |
109 | ### Our Standards
110 |
111 | Examples of behavior that contributes to a positive environment for our community include:
112 |
113 | - Demonstrating empathy and kindness toward other people
114 | - Being respectful of differing opinions, viewpoints, and experiences
115 | - Giving and gracefully accepting constructive feedback
116 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
117 | - Focusing on what is best not just for us as individuals, but for the overall community
118 |
119 | Examples of unacceptable behavior include:
120 |
121 | - The use of sexualized language or imagery, and sexual attention or
122 | advances of any kind
123 | - Trolling, insulting or derogatory comments, and personal or political attacks
124 | - Public or private harassment
125 | - Publishing others' private information, such as a physical or email
126 | address, without their explicit permission
127 | - Other conduct which could reasonably be considered inappropriate in a
128 | professional setting
129 |
130 | ### Enforcement Responsibilities
131 |
132 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
133 |
134 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
135 |
136 | ### Scope
137 |
138 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
139 |
140 | ### Enforcement
141 |
142 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly.
143 |
144 | All community leaders are obligated to respect the privacy and security of the reporter of any incident.
145 |
146 | ### Enforcement Guidelines
147 |
148 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
149 |
150 | #### 1. Correction
151 |
152 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
153 |
154 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
155 |
156 | #### 2. Warning
157 |
158 | **Community Impact**: A violation through a single incident or series of actions.
159 |
160 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
161 |
162 | #### 3. Temporary Ban
163 |
164 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
165 |
166 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
167 |
168 | #### 4. Permanent Ban
169 |
170 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
171 |
172 | **Consequence**: A permanent ban from any sort of public interaction within the community.
173 |
174 | ### Attribution
175 |
176 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
177 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
178 |
179 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
180 |
181 | [homepage]: https://www.contributor-covenant.org
182 |
183 | For answers to common questions about this code of conduct, see the FAQ at
184 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
185 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020-present DaniAkash
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |