Skip to content

Commit

Permalink
Merge pull request #40 from dabapps/use-requests
Browse files Browse the repository at this point in the history
Use requests
  • Loading branch information
AngryLawyer authored Mar 20, 2019
2 parents b30f4a9 + 35f2520 commit 4273505
Show file tree
Hide file tree
Showing 32 changed files with 1,837 additions and 4,590 deletions.
4 changes: 4 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "es5"
}
9 changes: 0 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,3 @@ install:
script:
- npm test
- npm run dist

deploy:
provider: npm
email: [email protected]
on:
tags: true
api_key:
secure: NiEYS2mfHM0O7HxZ+tLFe9YCjkaZB2cy2tHLGqGnWUdNM4CLRugbAreYRgewylbWoqwm3ge5G2PbDKpf19t6aB/RSDtjm4OcSfPZF2MM/s0K2Cnoh62TRbEnZHmaDF6v73GI1H6sxp3EQvHpGt3JyPblNelBkW1MbnlFPAmxiivRIBjEDPyCtwUE3SnnoTJM8ojmFOZL5sidXWH1S4iJslO3i4Y8LUISKOqr9etII9HuaxrIuf0H5rL8uWBnhw9A4y+dCRt6yBkfm4jTPg0s2T1oPQYLsu9OV2vmbmctu3D3qF2RG3k2m2NeWpIdicaEsLl2W9yBdXy1NRfNst85s40Gr5VW3DeHhC34In801rYHSSXcs/bMwXJ+pIFyAg/Q1BaJgbcLyXJghQznqXzWHyErmbi/0nnkVkny3QVajAZBialdNt+6Qh2bI7cDERkEA+ViOaRYoO48Xioxv8GqWPmdm1x/bsBU6CZlUgCd/7+Qdro9TFjAg/qPODpw8csORGWpFGDfk5z0r3Ki6XX6/ZunnMXZ88B91Hw+d29YlxuXOIljVZIWri1aVXymIa0OM6o+6lznIpJEBa73UiLdnafoY8ytxN0iWeQAET56WwfZepqgO2L+sRNiAWmnKOikJ3EmS7eGIXTgZ6X0pynLvLBDK/Wm2NCR1UiGKkzAiwo=
skip_cleanup: true
11 changes: 11 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Copyright (c) 2019 DabApps Ltd. - https://www.dabapps.com

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 changes: 15 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ Redux API Collections aims to simplify and standardise the way in which we acces
Install via NPM:

```
npm install @dabapps/redux-api-collections --save --save-exact
npm install @dabapps/redux-api-collections --save
```

To install you will need the company npm token set in your env `NPM_TOKEN=` and also add an `./npmrc` file (the same as the one included here), to be able to authenticate with NPM Private Repos.

## Getting Started
This project requires use of Redux-Thunk to correctly dispatch actions. Collection endpoints must follow Django Rest Framework's pagination logic. Item endpoints should return a single item.

Expand Down Expand Up @@ -59,8 +57,7 @@ const itemToRecordMapping = {
Now we have mappings, plus interfaces, we can bring it all together. You are likely to want to also mount the Responses reducer, as this gives visibility to which endpoints are currently in use.

```typescript
import { Collections } from 'redux-api-collections';
import { responsesReducer } from 'redux-api-collections/dist/requests';
import { Collections, responsesReducer } from '@dabapps/redux-api-collections';

const collections = Collections<Collections, Items>(collectionToRecordMapping, itemToRecordMapping);

Expand Down Expand Up @@ -89,6 +86,10 @@ getCollectionResultsByName(store.collections, 'users');

Many functions can also be namespaced by a `subgroup` field - this will allow you to request the same endpoint from multiple places without overwriting their results.

```typescript
const action = collections.actions.getCollection('users', options, 'loginPage');
```

## Subpaths

There are often situations where you want to have collections or items at a path with some form of ID in the middle of it. Provide your paths as something [path-to-regexp](https://github.com/pillarjs/path-to-regexp) understands:
Expand Down Expand Up @@ -125,23 +126,13 @@ itemSubpath.getSubpathItem(store);

## I'm stuck!

### Help, I want to use Immutable collections!

We've got you covered. When initializing Collections, set `useImmutableForCollections` to `true` in a configuration object to the third argument to automatically generate Immutable List based collections, which can then be retrieved via `getImmutableCollectionResultsByName`

```typescript
const collections = Collections<Collections, Items>(collectionToRecordMapping, itemToRecordMapping, { useImmutableForCollections: true });
```

However, we generate fresh `List`s with every change, as the internal APIs between `List`s and `ReadonlyArray`s are too dissimilar for the code to be generic across. This feature exists mostly for backwards compatibility with projects that are currently using Immutable.

### Help, my API isn't mounted at /api/

You can parameterize the Collections object with different base URLs, for those odd cases where your API is different from the others we use.


```typescript
import { Collections } from 'redux-api-collections';
import { Collections } from '@dabapps/redux-api-collections';
const collections = Collections<Collections, Items>(collectionToRecordMapping, itemToRecordMapping, { baseUrl: '/another-base-url/' });
```

Expand All @@ -151,7 +142,7 @@ const collections = Collections<Collections, Items>(collectionToRecordMapping, i
You can provide custom Reducers that will be called by the built-in ones for post-processing the state when actions come in.

```typescript
import { Collections } from 'redux-api-collections';
import { Collections } from '@dabapps/redux-api-collections';

function myCustomCollectionReducer(state: CollectionStore<Collections>, action: AnyAction): CollectionStore<Collections> {
// Usual Reducer stuff
Expand All @@ -162,7 +153,12 @@ function myCustomItemReducer(state: ItemStore<Items>, action: AnyAction): ItemSt
}

const collections = Collections<Collections, Items>(collectionToRecordMapping, itemToRecordMapping, {
collectionReducerPlugin: myCustomCollectionReducer,
itemReducerPlugin: myCustomItemReducer
collectionReducerPlugin: myCustomCollectionReducer,
itemReducerPlugin: myCustomItemReducer
});
```


## Code of conduct

For guidelines regarding the code of conduct when contributing to this repository please review [https://www.dabapps.com/open-source/code-of-conduct/](https://www.dabapps.com/open-source/code-of-conduct/)
Loading

0 comments on commit 4273505

Please sign in to comment.