-
Notifications
You must be signed in to change notification settings - Fork 95
Add initial code and dependencies #1
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f7f3227
Add initial code and dependencies
tgolen 8c8d268
Simplify the ignore file
tgolen 6ca62ad
Remove sublime link
tgolen 9241188
Rename to onyx
tgolen b4467e8
Move onyx to the lib folder
tgolen 6dae3a5
Add the HOC
tgolen ecc5163
Include react in the dependencies
tgolen 38ac6c9
More renaming
tgolen 093897a
Update code from master
tgolen 1c87015
Refactor storage event
tgolen bf228c3
Update js libs
tgolen 2ec059e
Add lodash libs
tgolen d5560e5
Import lodash and remove unused lodash modules
tgolen e0ea42b
Update JS-Libs
tgolen b200cb3
update lock file
tgolen 705f12b
Update js-libs
tgolen 100062c
Update to final JS libs hash
tgolen e01c243
Fix lint errors
tgolen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # EditorConfig is awesome: http://EditorConfig.org | ||
|
|
||
| # top-most EditorConfig file | ||
| root = true | ||
|
|
||
| # Unix-style newlines with a newline ending every file | ||
| [**] | ||
| end_of_line = lf | ||
| insert_final_newline = true | ||
| indent_style = space | ||
| indent_size = 4 | ||
|
|
||
| # Standard at: https://github.com/felixge/node-style-guide | ||
| [**.js, **.json] | ||
| trim_trailing_whitespace = true | ||
| quote_type = single | ||
| curly_bracket_next_line = false | ||
| spaces_around_operators = true | ||
| space_after_control_statements = true | ||
| space_after_anonymous_functions = false | ||
| spaces_in_brackets = false | ||
|
|
||
| # No Standard. Please document a standard if different from .js | ||
| [**.yml, **.html, **.css] | ||
| trim_trailing_whitespace = true | ||
|
|
||
| # No standard. Please document a standard if different from .js | ||
| [**.md] | ||
|
|
||
| # Standard at: | ||
| [Makefile] | ||
|
|
||
| [package*] | ||
| indent_style = space | ||
| indent_size = 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| module.exports = { | ||
| extends: 'expensify', | ||
| rules: { | ||
| // Overwriting this for now because web-e will conflict with this | ||
| 'react/jsx-filename-extension': [1, {extensions: ['.js']}], | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # OSX | ||
| # | ||
| .DS_Store | ||
|
|
||
| # node.js | ||
| # | ||
| node_modules/ | ||
| npm-debug.log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # React-Native-Onyx | ||
| This is a persistent storage solution wrapped in a Pub/Sub library. In general that means: | ||
|
|
||
| - Onyx stores and retrieves data from persistent storage | ||
| - Data is stored as key/value pairs, where the value can be anything from a single piece of data to a complex object | ||
| - Collections of data are usually not stored as a single key (eg. an array with multiple objects), but as individual keys+ID (eg. `report_1234`, `report_4567`, etc.). Store collections as individual keys when a component will bind directly to one of those keys. For example: reports are stored as individual keys because `SidebarLink.js` binds to the individual report keys for each link. However, report actions are stored as an array of objects because nothing binds directly to a single report action. | ||
| - Onyx allows other code to subscribe to changes in data, and then publishes change events whenever data is changed | ||
| - Anything needing to read Onyx data needs to: | ||
| 1. Know what key the data is stored in (for web, you can find this by looking in the JS console > Application > local storage) | ||
| 2. Subscribe to changes of the data for a particular key or set of keys. React components use `withOnyx()` and non-React libs use `Onyx.connect()`. | ||
| 3. Get initialized with the current value of that key from persistent storage (Onyx does this by calling `setState()` or triggering the `callback` with the values currently on disk as part of the connection process) | ||
| - Subscribing to Onyx keys is done using a constant defined in `IONKEYS`. Each Onyx key represents either a collection of items or a specific entry in storage. For example, since all reports are stored as individual keys like `report_1234`, if code needs to know about all the reports (eg. display a list of them in the nav menu), then it would subscribe to the key `IONKEYS.COLLECTION.REPORT`. | ||
|
|
||
| ### Storage Eviction | ||
|
|
||
| Different platforms come with varying storage capacities and Onyx has a way to gracefully fail when those storage limits are encountered. When Onyx fails to set or modify a key the following steps are taken: | ||
| 1. Onyx looks at a list of recently accessed keys (access is defined as subscribed to or modified) and locates the key that was least recently accessed | ||
| 2. It then deletes this key and retries the original operation | ||
|
|
||
| By default, Onyx will not evict anything from storage and will presume all keys are "unsafe" to remove unless explicitly told otherwise. | ||
|
|
||
| **To flag a key as safe for removal:** | ||
| - Add the key to the `safeEvictionKeys` option in `Onyx.init(options)` | ||
| - Implement `canEvict` in the Onyx config for each component subscribing to a key | ||
| - The key will only be deleted when all subscribers return `true` for `canEvict` | ||
|
|
||
| e.g. | ||
| ```js | ||
| Onyx.init({ | ||
| safeEvictionKeys: [IONKEYS.COLLECTION.REPORT_ACTIONS], | ||
| }); | ||
| ``` | ||
|
|
||
| ```js | ||
| export default withOnyx({ | ||
| reportActions: { | ||
| key: ({reportID}) => `${IONKEYS.COLLECTION.REPORT_ACTIONS}${reportID}_`, | ||
| canEvict: props => !props.isActiveReport, | ||
| }, | ||
| })(ReportActionsView); | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import Onyx from './lib/Onyx'; | ||
| import withOnyx from './lib/withOnyx'; | ||
|
|
||
| export default Onyx; | ||
| export {withOnyx}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Logging callback | ||
| let logger; | ||
|
|
||
| /** | ||
| * Register the logging callback | ||
| * | ||
| * @param {Function} callback | ||
| */ | ||
| function registerLogger(callback) { | ||
| logger = callback; | ||
| } | ||
|
|
||
| /** | ||
| * Send an alert message to the logger | ||
| * | ||
| * @param {String} message | ||
| */ | ||
| function logAlert(message) { | ||
| logger({message: `[Onyx] ${message}`, level: 'alert'}); | ||
| } | ||
|
|
||
| /** | ||
| * Send an info message to the logger | ||
| * | ||
| * @param {String} message | ||
| */ | ||
| function logInfo(message) { | ||
| logger({message: `[Onyx] ${message}`, level: 'info'}); | ||
| } | ||
|
|
||
| export { | ||
| registerLogger, | ||
| logInfo, | ||
| logAlert, | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not needed right now, but we might want to be more neutral with our examples if this is getting open sourced.