├── .gitignore
├── .travis.yml
├── .babelrc
├── rollup.config.js
├── CONTRIBUTING.md
├── LICENSE
├── CHANGELOG.md
├── package.json
├── README.md
└── src
├── index.js
└── __tests__
└── index.js
/.gitignore:
--------------------------------------------------------------------------------
1 | /coverage
2 | /demo/dist
3 | /dist
4 | /lib
5 | /es
6 | /node_modules
7 | /umd
8 | /es
9 | npm-debug.log
10 | .idea
11 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 |
3 | node_js:
4 | - "7"
5 |
6 | cache:
7 | directories:
8 | - node_modules
9 |
10 | before_install:
11 | - npm install codecov
12 |
13 | after_success:
14 | - cat ./coverage/lcov.info | ./node_modules/codecov/bin/codecov
15 |
16 | cache:
17 | directories:
18 | - node_modules
19 |
--------------------------------------------------------------------------------
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | [
4 | "env",
5 | {
6 | "modules": false,
7 | "loose": true
8 | }
9 | ],
10 | "stage-0",
11 | "react"
12 | ],
13 | "env": {
14 | "test": {
15 | "presets": [
16 | [
17 | "env",
18 | {
19 | "loose": true
20 | }
21 | ],
22 | "stage-0",
23 | "react"
24 | ]
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | import babel from 'rollup-plugin-babel';
2 | import fs from 'fs'
3 |
4 | const pkg = JSON.parse(fs.readFileSync('./package.json'))
5 |
6 | export default {
7 | entry: 'src/index.js',
8 | external: ['react'],
9 | exports: 'named',
10 | globals: { react: 'React' },
11 | useStrict: false,
12 | sourceMap: true,
13 | plugins: [babel({
14 | exclude: 'node_modules/**'
15 | })],
16 | targets: [
17 | {dest: pkg.main, format: 'cjs'},
18 | {dest: pkg.module, format: 'es'},
19 | {dest: pkg['umd:main'], format: 'umd', moduleName: pkg.name}
20 | ]
21 | }
22 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | ## Prerequisites
2 |
3 | [Node.js](http://nodejs.org/) >= v4 must be installed.
4 |
5 | ## Installation
6 |
7 | - Running `npm install` in the module's root directory will install everything you need for development.
8 |
9 | ## Running Tests
10 |
11 | - `npm test` will run the tests once.
12 |
13 | - `npm run test:coverage` will run the tests and produce a coverage report in `coverage/`.
14 |
15 | - `npm run test:watch` will run the tests on every change.
16 |
17 | ## Building
18 |
19 | - `npm run build` will build the module for publishing to npm.
20 |
21 | - `npm run clean` will delete built resources.
22 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Kye Hohenberger
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 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Changelog
2 | ------------
3 |
4 | ##### 2.0.0
5 | * Action creators now receive ONE arguement, `store`.
6 | This expands what is possible in an action handler
7 |
8 | * Renamed `addReducer` to `handleActions` (inspired by redux-actions)
9 | The name no longer made sense. Returning a _new_ state from the handler is no longer required.
10 |
11 | * Added `createActions` (inspired by redux-actions)
12 |
13 | Allows developer to create actions and have them available directly from the store
14 | ```js
15 | store.createActions({
16 | startMediaStream: (constraints) => async store => {
17 | try {
18 | const stream = await navigator.mediaDevices.getUserMedia(constraints)
19 | store.actions.mediaStreamSuccess(stream)
20 | } catch (err) {
21 | store.actions.mediaStreamError(err)
22 | }
23 | },
24 | addImage: 'camera/ADD_IMAGE'
25 | })
26 |
27 | // ...later
28 | store.actions.startMediaStream({ audio: true, video: true })
29 | store.actions.addImage(image)
30 | ```
31 |
32 | If the property of the action creator is a plain string like `addImage: 'camera/ADD_IMAGE'` you can use the name in your reducer.
33 |
34 | ```js
35 | store.handleActions({
36 | [store.actions.addImage]: (state, image) => {
37 | state.camera.images.push(image)
38 | }
39 | })
40 | ```
41 |
42 | * Reserved event types with the prefix `$$store:`
43 | `$$store:state:change` is fired after an action handler is called
44 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "holen",
3 | "version": "2.0.0",
4 | "description": "Declarative fetch in React",
5 | "jsnext:main": "dist/holen.es.js",
6 | "module": "dist/holen.es.js",
7 | "main": "dist/holen.js",
8 | "umd:main": "dist/holen.umd.js",
9 | "files": [
10 | "dist"
11 | ],
12 | "scripts": {
13 | "build": "npm-run-all clean -p rollup -p minify:* -s size",
14 | "clean": "rimraf dist",
15 | "test": "standard src test && jest --coverage",
16 | "test:watch": "jest --watch",
17 | "rollup": "rollup -c",
18 | "minify:cjs": "uglifyjs $npm_package_main -cm toplevel -o $npm_package_main -p relative --in-source-map ${npm_package_main}.map --source-map ${npm_package_main}.map",
19 | "minify:umd": "uglifyjs $npm_package_umd_main -cm -o $npm_package_umd_main -p relative --in-source-map ${npm_package_umd_main}.map --source-map ${npm_package_umd_main}.map",
20 | "size": "echo \"Gzipped Size: $(strip-json-comments --no-whitespace $npm_package_main | gzip-size)\"",
21 | "release": "npm run test && npm run build && npm version patch && npm publish && git push --tags"
22 | },
23 | "peerDependencies": {
24 | "react": ">=14"
25 | },
26 | "devDependencies": {
27 | "babel-eslint": "^7.2.3",
28 | "babel-jest": "^19.0.0",
29 | "babel-polyfill": "^6.23.0",
30 | "babel-preset-env": "^1.4.0",
31 | "babel-preset-react": "^6.24.1",
32 | "babel-preset-stage-0": "^6.24.1",
33 | "gzip-size-cli": "^2.0.0",
34 | "hapi": "^16.1.0",
35 | "isomorphic-unfetch": "^2.0.0",
36 | "jest": "^19.0.2",
37 | "npm-run-all": "^4.0.2",
38 | "pretty-bytes-cli": "^2.0.0",
39 | "prop-types": "^15.5.8",
40 | "raw-loader": "^0.5.1",
41 | "react": "^15.5.4",
42 | "react-addons-test-utils": "^15.5.1",
43 | "react-dom": "^15.5.4",
44 | "rimraf": "^2.6.1",
45 | "rollup": "^0.41.6",
46 | "rollup-plugin-babel": "^2.7.1",
47 | "standard": "^10.0.2",
48 | "strip-json-comments-cli": "^1.0.1",
49 | "uglify-js": "^2.8.22"
50 | },
51 | "author": "Kye Hohenberger",
52 | "homepage": "https://github.com/tkh44/holen#readme",
53 | "license": "MIT",
54 | "repository": {
55 | "type": "git",
56 | "url": "git+https://github.com/tkh44/holen.git"
57 | },
58 | "directories": {
59 | "test": "tests"
60 | },
61 | "keywords": [
62 | "fetch",
63 | "react",
64 | "react-component",
65 | "react-fetch",
66 | "fetch-component",
67 | "preact",
68 | "preact-fetch",
69 | "holen"
70 | ],
71 | "eslintConfig": {
72 | "extends": "standard",
73 | "parser": "babel-eslint"
74 | },
75 | "standard": {
76 | "parser": "babel-eslint",
77 | "ignore": [
78 | "/dist/"
79 | ]
80 | },
81 | "bugs": {
82 | "url": "https://github.com/tkh44/holen/issues"
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Holen
4 | Declarative fetch in React
5 |
6 | [](https://badge.fury.io/js/holen)
7 | [](https://travis-ci.org/tkh44/holen)
8 | [](https://codecov.io/gh/tkh44/holen)
9 |
10 | - [Install](#install)
11 | - [Basic Usage](#basic-usage)
12 |
13 | ## Install
14 |
15 | ```bash
16 | npm install -S holen
17 | ```
18 |
19 | ## Basic Usage
20 | ```jsx
21 | // Fetch on mount
22 | {JSON.stringify(data, null, 2)}}
24 | {JSON.stringify(data, null, 2)}
32 | {JSON.stringify(data, null, 2)}}
48 | {JSON.stringify(data, null , 2)}
115 |