Skip to content

Commit

Permalink
v0.14.0 (#309)
Browse files Browse the repository at this point in the history
* fix: preserve id on document modified reordering (#308) - @puppybits
* fix(types): de-dupe action types by reusing existing const (#290) - @msutkowski
* fix(docs): enhanced example in README (#286) - @gregfenton
* build(deps): update lodash to 4.17.20
* build(deps): bump elliptic from 6.5.2 to 6.5.3 (#302)
* build(deps): bump elliptic from 6.5.1 to 6.5.3 in /examples/basic (#301)
* build(deps): bump http-proxy from 1.18.0 to 1.18.1 in /examples/basic (#306)
* build(deps): bump handlebars from 4.5.1 to 4.7.6 in /examples/basic (#305)
* build(deps-dev): bump codecov from 3.6.5 to 3.7.1 (#300)

Co-authored-by: Bobby <[email protected]>
Co-authored-by: gregfenton <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Matt Sutkowski <[email protected]>
  • Loading branch information
5 people authored Sep 30, 2020
1 parent 1de985c commit 2a26111
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 107 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,13 @@ _Can only be used with collections. Types can be a string, number, Date object,
```js
{
collection: 'cities',
orderBy: 'population',
startAfter: 1000000
orderBy: [['state', 'asc'],['population','desc']]
startAfter: ["CA", 1000000]
},
```

**Note:** for the above to return valid results, there must be at least one document with `state = "CA"` _and_ `population = 1000000` (i.e. the values idenify "the provided document").

_Can only be used with collections. Types can be a string, number, Date object, or an array of these types, but not a Firestore Document Snapshot_

##### endAt
Expand Down Expand Up @@ -462,7 +464,7 @@ Storing data under a different path within redux is as easy as passing the `stor
},
```

**NOTE:** Usage of `"/"` and `"."` within `storeAs` can cause unexpected behavior when attempting to retrieve from redux state
**Note:** Usage of `"/"` and `"."` within `storeAs` can cause unexpected behavior when attempting to retrieve from redux state

#### Other Firebase Statics

Expand Down Expand Up @@ -684,7 +686,7 @@ It can be imported like so:
</script>
```

Note: In an effort to keep things simple, the wording from this explanation was modeled after [the installation section of the Redux Docs](https://redux.js.org/#installation).
**Note:** In an effort to keep things simple, the wording from this explanation was modeled after [the installation section of the Redux Docs](https://redux.js.org/#installation).

## Applications Using This

Expand Down
88 changes: 33 additions & 55 deletions examples/basic/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2192,9 +2192,9 @@ bluebird@^3.5.5:
integrity sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w==

bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0:
version "4.11.8"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f"
integrity sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==
version "4.11.9"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.9.tgz#26d556829458f9d1e81fc48952493d0ba3507828"
integrity sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==

[email protected]:
version "1.19.0"
Expand Down Expand Up @@ -2806,7 +2806,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf"
integrity sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg==

commander@^2.11.0, commander@~2.20.0:
commander@^2.11.0:
version "2.20.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.1.tgz#3863ce3ca92d0831dcf2a102f5fb4b5926afd0f9"
integrity sha512-cCuLsMhJeWQ/ZpsFTbE765kvVfoeSddc4nU3up4fV+fDBcfUXnbITJ+JzhkdjzOqhURjZgujxaioam4RM9yGUg==
Expand Down Expand Up @@ -3319,7 +3319,7 @@ [email protected], debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.8, debug@^2.6.
dependencies:
ms "2.0.0"

debug@^3.0.0, debug@^3.1.0, debug@^3.2.5, debug@^3.2.6:
debug@^3.1.0, debug@^3.2.5, debug@^3.2.6:
version "3.2.6"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==
Expand Down Expand Up @@ -3664,9 +3664,9 @@ electron-to-chromium@^1.3.247:
integrity sha512-426qbfgLn0hVE4pDxok2dcAhA3u5lwXlBg2+i6VWQJvnMZNgevkC6s/qr91YH/avVMKXKwxnR5iBznpivg210A==

elliptic@^6.0.0:
version "6.5.1"
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.1.tgz#c380f5f909bf1b9b4428d028cd18d3b0efd6b52b"
integrity sha512-xvJINNLbTeWQjrl6X+7eQCrIy/YPv5XCpKW6kB5mKvtnGILoLDcySuwomfdzt0BMdLNVnuRNTuzKNHj0bva1Cg==
version "6.5.3"
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.3.tgz#cb59eb2efdaf73a0bd78ccd7015a62ad6e0f93d6"
integrity sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==
dependencies:
bn.js "^4.4.0"
brorand "^1.0.1"
Expand Down Expand Up @@ -3988,9 +3988,9 @@ etag@~1.8.1:
integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=

eventemitter3@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.0.tgz#d65176163887ee59f386d64c82610b696a4a74eb"
integrity sha512-qerSRB0p+UDEssxTtm6EDKcE7W4OaoisfIMl4CngyEhjpYglocpNg6UEqCvemdGhosAsg4sO2dXJOdyBifPGCg==
version "4.0.7"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f"
integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==

events@^3.0.0:
version "3.0.0"
Expand Down Expand Up @@ -4424,11 +4424,9 @@ flush-write-stream@^1.0.0:
readable-stream "^2.3.6"

follow-redirects@^1.0.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.9.0.tgz#8d5bcdc65b7108fe1508649c79c12d732dcedb4f"
integrity sha512-CRcPzsSIbXyVDl0QI01muNDu69S8trU4jArW9LpOt2WtC6LyUJetcIrmfHsRBx7/Jb6GHJUiuqyYxPooFfNt6A==
dependencies:
debug "^3.0.0"
version "1.13.0"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.0.tgz#b42e8d93a2a7eea5ed88633676d6597bc8e384db"
integrity sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==

for-in@^0.1.3:
version "0.1.8"
Expand Down Expand Up @@ -4799,13 +4797,14 @@ handle-thing@^2.0.0:
integrity sha512-d4sze1JNC454Wdo2fkuyzCr6aHcbL6PGGuFAz0Li/NcOm1tCHGnWDRmJP85dh9IhQErTc2svWFEX5xHIOo//kQ==

handlebars@^4.0.3:
version "4.5.1"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.5.1.tgz#8a01c382c180272260d07f2d1aa3ae745715c7ba"
integrity sha512-C29UoFzHe9yM61lOsIlCE5/mQVGrnIOrOq7maQl76L7tYPCgC1og0Ajt6uWnX4ZTxBPnjw+CUvawphwCfJgUnA==
version "4.7.6"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.6.tgz#d4c05c1baf90e9945f77aa68a7a219aa4a7df74e"
integrity sha512-1f2BACcBfiwAfStCKZNrUCgqNZkGsAT7UM3kkYtXuLo0KnaVfjKOyf7PRzB6++aK9STyT1Pd2ZCPe3EGOXleXA==
dependencies:
minimist "^1.2.5"
neo-async "^2.6.0"
optimist "^0.6.1"
source-map "^0.6.1"
wordwrap "^1.0.0"
optionalDependencies:
uglify-js "^3.1.4"

Expand Down Expand Up @@ -5090,9 +5089,9 @@ http-proxy-middleware@~0.18.0:
micromatch "^3.1.9"

http-proxy@^1.16.2:
version "1.18.0"
resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.18.0.tgz#dbe55f63e75a347db7f3d99974f2692a314a6a3a"
integrity sha512-84I2iJM/n1d4Hdgc6y2+qY5mDaz2PUVjlg9znE9byl+q0uC3DeByqBGReQu5tpLK0TAqTIXScRUV+dg7+bUPpQ==
version "1.18.1"
resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.18.1.tgz#401541f0534884bbf95260334e72f88ee3976549"
integrity sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==
dependencies:
eventemitter3 "^4.0.0"
follow-redirects "^1.0.0"
Expand Down Expand Up @@ -6781,15 +6780,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=

minimist@^1.1.1, minimist@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"
integrity sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=

minimist@~0.0.1:
version "0.0.10"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"
integrity sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=
minimist@^1.1.1, minimist@^1.2.0, minimist@^1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==

minipass@^2.6.0, minipass@^2.8.6, minipass@^2.9.0:
version "2.9.0"
Expand Down Expand Up @@ -6948,9 +6942,9 @@ [email protected]:
integrity sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==

neo-async@^2.5.0, neo-async@^2.6.0:
version "2.6.1"
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.1.tgz#ac27ada66167fa8849a6addd837f6b189ad2081c"
integrity sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw==
version "2.6.2"
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f"
integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==

nice-try@^1.0.4:
version "1.0.5"
Expand Down Expand Up @@ -7315,14 +7309,6 @@ opn@^5.1.0:
dependencies:
is-wsl "^1.1.0"

optimist@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686"
integrity sha1-2j6nRob6IaGaERwybpDrFaAZZoY=
dependencies:
minimist "~0.0.1"
wordwrap "~0.0.2"

[email protected]:
version "5.0.1"
resolved "https://registry.yarnpkg.com/optimize-css-assets-webpack-plugin/-/optimize-css-assets-webpack-plugin-5.0.1.tgz#9eb500711d35165b45e7fd60ba2df40cb3eb9159"
Expand Down Expand Up @@ -10242,12 +10228,9 @@ [email protected]:
source-map "~0.6.1"

uglify-js@^3.1.4:
version "3.6.0"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.6.0.tgz#704681345c53a8b2079fb6cec294b05ead242ff5"
integrity sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==
dependencies:
commander "~2.20.0"
source-map "~0.6.1"
version "3.10.4"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.10.4.tgz#dd680f5687bc0d7a93b14a3482d16db6eba2bfbb"
integrity sha512-kBFT3U4Dcj4/pJ52vfjCSfyLyvG9VYYuGYPmrPvAxRw/i7xHiT4VvCev+uiEMcEEiu6UNB6KgWmGtSUYIWScbw==

uglifyjs-webpack-plugin@^1.2.4:
version "1.3.0"
Expand Down Expand Up @@ -10700,12 +10683,7 @@ window-size@^0.1.4:
resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.4.tgz#f8e1aa1ee5a53ec5bf151ffa09742a6ad7697876"
integrity sha1-+OGqHuWlPsW/FR/6CXQqatdpeHY=

wordwrap@~0.0.2:
version "0.0.3"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107"
integrity sha1-o9XabNXAvAAI03I0u68b7WMFkQc=

wordwrap@~1.0.0:
wordwrap@^1.0.0, wordwrap@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
integrity sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=
Expand Down
41 changes: 10 additions & 31 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,43 +34,20 @@ export const actionTypes: {
ON_SNAPSHOT_REQUEST: string;
ON_SNAPSHOT_SUCCESS: string;
ON_SNAPSHOT_FAILURE: string;
DOCUMENT_ADDED: string;
DOCUMENT_MODIFIED: string;
DOCUMENT_REMOVED: string;
TRANSACTION_START: string;
TRANSACTION_SUCCESS: string;
TRANSACTION_FAILURE: string;
};

/**
* Constants used within redux-firetore. Includes actionTypes, actionsPrefix,
* and default config.
*/
export const constants: {
actionTypes: {
START: string;
ERROR: string;
CLEAR_DATA: string;
CLEAR_ERROR: string;
CLEAR_ERRORS: string;
SET_LISTENER: string;
UNSET_LISTENER: string;
GET_REQUEST: string;
GET_SUCCESS: string;
GET_FAILURE: string;
SET_REQUEST: string;
SET_SUCCESS: string;
SET_FAILURE: string;
ADD_REQUEST: string;
ADD_SUCCESS: string;
ADD_FAILURE: string;
UPDATE_REQUEST: string;
UPDATE_SUCCESS: string;
UPDATE_FAILURE: string;
DELETE_REQUEST: string;
DELETE_SUCCESS: string;
DELETE_FAILURE: string;
ATTACH_LISTENER: string;
LISTENER_RESPONSE: string;
LISTENER_ERROR: string;
ON_SNAPSHOT_REQUEST: string;
ON_SNAPSHOT_SUCCESS: string;
ON_SNAPSHOT_FAILURE: string;
};
actionTypes: typeof actionTypes;
actionsPrefix: string;
defaultConfig: Config;
};
Expand Down Expand Up @@ -98,7 +75,9 @@ export interface Config {
preserveOnListenerError: null | object;

// https://github.com/prescottprue/redux-firestore#onattemptcollectiondelete
onAttemptCollectionDelete: null | ((queryOption: string, dispatch: Dispatch, firebase: Object) => void);
onAttemptCollectionDelete:
| null
| ((queryOption: string, dispatch: Dispatch, firebase: Object) => void);

// https://github.com/prescottprue/redux-firestore#mergeordered
mergeOrdered: boolean;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-firestore",
"version": "0.13.0",
"version": "0.14.0",
"description": "Redux bindings for Firestore.",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down Expand Up @@ -36,7 +36,7 @@
},
"dependencies": {
"immer": "5.0.0",
"lodash": "^4.17.15",
"lodash": "^4.17.20",
"reduce-reducers": "^1.0.4"
},
"devDependencies": {
Expand Down
16 changes: 10 additions & 6 deletions src/reducers/orderedReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ const {

/**
* Create a new copy of an array with the provided item in a new array index
*
* @param {Array} [collectionState=[]] - Redux state of current collection
* @param {object} meta - New array metadata
* @param {object} meta.oldIndex - New array index for the item
* @param {object} meta.newIndex -
* @param {object} meta - Redux Action meta data contains the doc id
* @param {object} ordered - New array metadata
* @param {object} ordered.oldIndex - New array index for the item
* @param {object} ordered.newIndex -
* @param {object} newValue - New value of the item
* @returns {Array} Array with item moved
*/
function newArrayWithItemMoved(collectionState, meta, newValue) {
const { oldIndex, newIndex } = meta || {};
function newArrayWithItemMoved(collectionState, meta, ordered, newValue) {
const { doc } = meta;
const { oldIndex, newIndex } = ordered || {};
// remove oldIndex from array while creating a copy
const arrayWithoutItem = [
...collectionState.slice(0, oldIndex),
Expand All @@ -38,7 +41,7 @@ function newArrayWithItemMoved(collectionState, meta, newValue) {
return [
...arrayWithoutItem.slice(0, newIndex),
// set new item (falling back to using a copy of the removed item)
newValue || { ...collectionState[oldIndex] },
{ id: doc, ...newValue } || { ...collectionState[oldIndex] },
...arrayWithoutItem.slice(newIndex),
];
}
Expand All @@ -59,6 +62,7 @@ function modifyDoc(collectionState, action) {
if (!!newIndex && oldIndex > -1 && newIndex !== oldIndex) {
return newArrayWithItemMoved(
collectionState,
action.meta,
action.payload.ordered,
action.payload.data,
);
Expand Down
39 changes: 39 additions & 0 deletions test/unit/reducers/orderedReducer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,45 @@ describe('orderedReducer', () => {
});

describe('DOCUMENT_MODIFIED', () => {
it('preserves id on existing document when reordered', () => {
const collection = 'test1';
const doc = 'test2';
const someDoc = { some: 'value' };
const otherDoc = { id: 'id1' };
const newIndex = 2;
const oldIndex = 0;
const payload = {
ordered: { newIndex, oldIndex },
data: someDoc,
};
const meta = { collection, doc };
action = { meta, payload, type: actionTypes.DOCUMENT_MODIFIED };
const fakeState = {
[collection]: [someDoc, otherDoc, { id: 'id2' }],
};
const result = orderedReducer(fakeState, action);
// ID on first item no longer matches
expect(result).to.not.have.nested.property(
`${collection}.${oldIndex}.id`,
doc,
);
// Old item is moved into removed index
expect(result).to.have.nested.property(
`${collection}.${oldIndex}.id`,
otherDoc.id,
);
// Value is set to new item index
expect(result).to.have.nested.property(
`${collection}.${newIndex}.some`,
someDoc.some,
);
// Moved item's id is preserved
expect(result).to.have.nested.property(
`${collection}.${newIndex}.id`,
doc,
);
});

it('preserves id on existing document - #252', () => {
const collection = 'test1';
const doc = 'test2';
Expand Down
Loading

0 comments on commit 2a26111

Please sign in to comment.