Skip to content

Commit

Permalink
Merge branch 'main' into @chrispader/feat/use-json-patch-for-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Pader committed Jul 4, 2023
2 parents e022710 + a33f604 commit e1f1ac0
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 330 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@ jobs:
steps:
- uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: "16.x"
cache: npm
cache-dependency-path: package-lock.json

- run: npm ci

Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
push:
branches: [main]

# Ensure that only once instance of this workflow executes at a time.
# If multiple PRs are merged in quick succession, there will only ever be one publish workflow running and one pending.
concurrency: ${{ github.workflow }}

jobs:
version:
runs-on: ubuntu-latest
Expand All @@ -13,15 +17,9 @@ jobs:
if: ${{ github.actor != 'OSBotify' }}

steps:
# Running this action ensures that only one instance of this job will run at a time.
# This is important to prevent race conditions when multiple pull requests are merged in quick succession
- uses: softprops/turnstyle@8db075d65b19bf94e6e8687b504db69938dc3c65
with:
poll-interval-seconds: 10
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/checkout@v3
with:
ref: main

- name: Decrypt & Import OSBotify GPG key
run: |
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# `react-native-onyx`
Persistent storage solution wrapped in a Pub/Sub library.
Awesome persistent storage solution wrapped in a Pub/Sub library.

# Features

Expand Down Expand Up @@ -222,7 +222,7 @@ function signOut() {
```

## Storage Providers
Onyx.get/set and the rest of the API accesses the underlying storage
`Onyx.get`, `Onyx.set`, and the rest of the API accesses the underlying storage
differently depending on the platform

Under the hood storage access calls are delegated to a [`StorageProvider`](lib/storage/index.web.js)
Expand Down
10 changes: 5 additions & 5 deletions lib/Onyx.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint-disable no-continue */
import _ from 'underscore';
import Str from 'expensify-common/lib/str';
import {deepEqual} from 'fast-equals';
import lodashGet from 'lodash/get';
import Storage from './storage';
import _ from 'underscore';
import * as Logger from './Logger';
import cache from './OnyxCache';
import * as Str from './Str';
import createDeferredTask from './createDeferredTask';
import fastMerge from './fastMerge';
import * as PerformanceUtils from './metrics/PerformanceUtils';
import Storage from './storage';

// Method constants
const METHOD = {
Expand Down Expand Up @@ -374,7 +374,7 @@ function keysChanged(collectionKey, partialCollection) {
// returned by the selector.
if (subscriber.selector) {
subscriber.withOnyxInstance.setState((prevState) => {
const previousData = reduceCollectionWithSelector(prevState[subscriber.statePropertyName], subscriber.selector, subscriber.withOnyxInstance.state);
const previousData = prevState[subscriber.statePropertyName];
const newData = reduceCollectionWithSelector(cachedCollection, subscriber.selector, subscriber.withOnyxInstance.state);

if (!deepEqual(previousData, newData)) {
Expand Down Expand Up @@ -504,7 +504,7 @@ function keyChanged(key, data, canUpdateSubscriber) {
};
const prevDataWithNewData = {
...prevData,
[key]: getSubsetOfData(data, subscriber.selector, subscriber.withOnyxInstance.state),
...newData,
};
if (!deepEqual(prevData, prevDataWithNewData)) {
PerformanceUtils.logSetStateCall(subscriber, prevData, newData, 'keyChanged', key);
Expand Down
29 changes: 29 additions & 0 deletions lib/Str.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import _ from 'underscore';

/**
* Returns true if the haystack begins with the needle
*
* @param {String} haystack The full string to be searched
* @param {String} needle The case-sensitive string to search for
* @return {Boolean} Returns true if the haystack starts with the needle.
*/
function startsWith(haystack, needle) {
return _.isString(haystack)
&& _.isString(needle)
&& haystack.startsWith(needle);
}

/**
* Checks if parameter is a string or function.
* If it is a string, then we will just return it.
* If it is a function, then we will call it with
* any additional arguments and return the result.
*
* @param {String|Function} parameter
* @returns {*}
*/
function result(parameter, ...args) {
return _.isFunction(parameter) ? parameter(...args) : parameter;
}

export {startsWith, result};
4 changes: 2 additions & 2 deletions lib/withOnyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* something in Onyx (a key/value store). That way, as soon as data in Onyx changes, the state will be set and the view
* will automatically change to reflect the new data.
*/
import PropTypes from 'prop-types';
import React from 'react';
import _ from 'underscore';
import PropTypes from 'prop-types';
import Str from 'expensify-common/lib/str';
import Onyx from './Onyx';
import * as Str from './Str';

/**
* Returns the display name of a component
Expand Down
Loading

0 comments on commit e1f1ac0

Please sign in to comment.