Skip to content
This repository was archived by the owner on Dec 6, 2023. It is now read-only.

Commit e39f263

Browse files
committed
Initial commit for pulling over reactotron-redux
0 parents  commit e39f263

31 files changed

+1043
-0
lines changed

Diff for: .babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": [ "es2015", "stage-1" ]
3+
}

Diff for: .circleci/config.yml

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Javascript Node CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
4+
#
5+
6+
defaults: &defaults
7+
docker:
8+
- image: circleci/node:10.11
9+
working_directory: ~/repo
10+
11+
version: 2
12+
jobs:
13+
setup:
14+
<<: *defaults
15+
steps:
16+
- checkout
17+
- restore_cache:
18+
name: Restore node modules
19+
keys:
20+
- v1-dependencies-{{ checksum "package.json" }}
21+
# fallback to using the latest cache if no exact match is found
22+
- v1-dependencies-
23+
- run:
24+
name: Install dependencies
25+
command: yarn install
26+
- save_cache:
27+
name: Save node modules
28+
paths:
29+
- node_modules
30+
key: v1-dependencies-{{ checksum "package.json" }}
31+
32+
tests:
33+
<<: *defaults
34+
steps:
35+
- checkout
36+
- restore_cache:
37+
name: Restore node modules
38+
keys:
39+
- v1-dependencies-{{ checksum "package.json" }}
40+
# fallback to using the latest cache if no exact match is found
41+
- v1-dependencies-
42+
- run:
43+
name: Run tests
44+
command: yarn ci:test
45+
46+
build:
47+
<<: *defaults
48+
steps:
49+
- checkout
50+
- restore_cache:
51+
name: Restore node modules
52+
keys:
53+
- v1-dependencies-{{ checksum "package.json" }}
54+
# fallback to using the latest cache if no exact match is found
55+
- v1-dependencies-
56+
- run:
57+
name: Run Build
58+
command: yarn build
59+
- save_cache:
60+
name: Save node modules
61+
paths:
62+
- dist
63+
key: v1-build-{{ .Branch }}-{{ .Revision }}
64+
65+
publish:
66+
<<: *defaults
67+
steps:
68+
- checkout
69+
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
70+
- restore_cache:
71+
name: Restore node modules
72+
keys:
73+
- v1-dependencies-{{ checksum "package.json" }}
74+
# fallback to using the latest cache if no exact match is found
75+
- v1-dependencies-
76+
- restore_cache:
77+
name: Restore build
78+
keys:
79+
- v1-build-{{ .Branch }}-{{ .Revision }}
80+
- run:
81+
name: Publish to NPM
82+
command: yarn ci:publish
83+
84+
workflows:
85+
version: 2
86+
test_and_release:
87+
jobs:
88+
- setup
89+
- tests:
90+
requires:
91+
- setup
92+
- build:
93+
requires:
94+
- tests
95+
- publish:
96+
requires:
97+
- build
98+
filters:
99+
branches:
100+
only: master

Diff for: .gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules
2+
npm-debug.log
3+
coverage
4+
.nyc_output
5+
dist
6+
.rpt2_cache
7+
.prettierrc
8+
compiled

Diff for: .releaserc

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"plugins": [
3+
"@semantic-release/commit-analyzer",
4+
"@semantic-release/release-notes-generator",
5+
"@semantic-release/npm",
6+
"@semantic-release/github",
7+
[
8+
"@semantic-release/git",
9+
{
10+
"assets": "package.json",
11+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
12+
}
13+
]
14+
]
15+
}

Diff for: LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 - 3016 Infinite Red LLC.
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.

Diff for: README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# reactotron-redux
2+
3+
This provides the redux ability to reactotron
4+
5+
Issue are tracked in the `reactotron` repository currently. That can be found at https://github.com/infinitered/reactotron/issues
6+
7+
TODO: Write all the other stuff

Diff for: package.json

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"name": "reactotron-redux",
3+
"version": "2.1.0",
4+
"description": "A Reactotron plugin for Redux.",
5+
"files": [
6+
"dist",
7+
"LICENSE",
8+
"README.md",
9+
"reactotron-redux.d.ts"
10+
],
11+
"main": "dist/index.js",
12+
"types": "./reactotron-redux.d.ts",
13+
"scripts": {
14+
"test": "ava",
15+
"watch": "ava --watch",
16+
"format": "prettier --write {**,.}/*.js && standard --fix",
17+
"coverage": "nyc ava",
18+
"build": "rollup -c ",
19+
"lint": "standard",
20+
"ci:test": "yarn test",
21+
"ci:publish": "yarn semantic-release",
22+
"semantic-release": "semantic-release"
23+
},
24+
"author": "Infinite Red",
25+
"bugs": {
26+
"url": "https://github.com/reactotron/reactotron/issues"
27+
},
28+
"devDependencies": {
29+
"@semantic-release/git": "^7.0.5",
30+
"ava": "^0.20.0",
31+
"babel-core": "^6.25.0",
32+
"babel-eslint": "^8.2.1",
33+
"babel-preset-es2015": "^6.24.1",
34+
"babel-preset-es2015-rollup": "^3.0.0",
35+
"babel-preset-stage-1": "^6.24.1",
36+
"mockery": "^2.1.0",
37+
"nyc": "^11.0.3",
38+
"prettier": "^1.10.2",
39+
"rollup": "^0.43.0",
40+
"rollup-plugin-babel": "^2.6.1",
41+
"standard": "^10.0.3"
42+
},
43+
"homepage": "https://github.com/reactotron/reactotron",
44+
"license": "MIT",
45+
"ava": {
46+
"require": [
47+
"babel-core/register"
48+
],
49+
"babel": {
50+
"babelrc": false,
51+
"presets": [
52+
"es2015",
53+
"stage-1"
54+
]
55+
}
56+
},
57+
"standard": {
58+
"parser": "babel-eslint"
59+
},
60+
"repository": "https://github.com/reactotron/reactotron/tree/master/packages/reactotron-redux",
61+
"dependencies": {
62+
"ramda": "^0.24.1",
63+
"ramdasauce": "^2.0.0",
64+
"reactotron-core-client": "^2.1.4",
65+
"redux": "^3.7.1"
66+
}
67+
}

Diff for: rollup.config.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import babel from 'rollup-plugin-babel'
2+
3+
export default {
4+
entry: 'src/index.js',
5+
format: 'cjs',
6+
plugins: [
7+
babel({
8+
babelrc: false,
9+
runtimeHelpers: true,
10+
presets: ['es2015-rollup', 'stage-1']
11+
})
12+
],
13+
dest: 'dist/index.js',
14+
external: ['ramda', 'redux', 'ramdasauce']
15+
}

Diff for: src/create-action-tracker.js

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { is, concat, merge, any } from 'ramda'
2+
import { DEFAULT_REPLACER_TYPE } from './replacement-reducer'
3+
4+
const DEFAULTS = {
5+
// except: [] // which actions
6+
}
7+
8+
// create the store enhancer
9+
export default (reactotron, trackerOptions = {}) => {
10+
// verify reactotron is sane
11+
if (!(is(Object, reactotron) && typeof reactotron.use === 'function')) {
12+
throw new Error('invalid reactotron passed')
13+
}
14+
15+
// assemble a crack team of options to use
16+
const options = merge(DEFAULTS, trackerOptions)
17+
const exceptions = concat([DEFAULT_REPLACER_TYPE], options.except || [])
18+
19+
// the store enhancer
20+
return next => (reducer, initialState, enhancer) => {
21+
// create the original store
22+
const store = next(reducer, initialState, enhancer)
23+
24+
// return a new store
25+
return {
26+
// featuring the properties of the original store
27+
...store,
28+
29+
// and a brand new dispatch function that wraps the old dispatch
30+
dispatch: action => {
31+
// start a timer
32+
const elapsed = reactotron.startTimer()
33+
34+
// call the original dispatch that actually does the real work
35+
const result = store.dispatch(action)
36+
37+
// stop the timer
38+
const ms = elapsed()
39+
40+
var unwrappedAction =
41+
action.type === 'PERFORM_ACTION' && action.action ? action.action : action
42+
43+
// if matchException is true, actionType is matched with exception
44+
const matchException = (exception, actionType) => {
45+
if (typeof exception === 'string') {
46+
return actionType === exception
47+
} else if (typeof exception === 'function') {
48+
return exception(actionType)
49+
} else if (exception instanceof RegExp) {
50+
return exception.test(actionType)
51+
} else {
52+
return false
53+
}
54+
}
55+
56+
const matchExceptions = any(
57+
exception => matchException(exception, unwrappedAction.type),
58+
exceptions
59+
)
60+
61+
// action not blacklisted?
62+
// if matchException is true, action.type is matched with exception
63+
if (!matchExceptions) {
64+
// check if the app considers this important
65+
let important = false
66+
if (trackerOptions && typeof trackerOptions.isActionImportant === 'function') {
67+
important = !!trackerOptions.isActionImportant(unwrappedAction)
68+
}
69+
70+
reactotron.reportReduxAction(unwrappedAction, ms, important)
71+
}
72+
73+
return result
74+
}
75+
}
76+
}
77+
}

Diff for: src/create-store.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { createStore, compose } from 'redux'
2+
3+
export default (reactotron, rootReducer, preloadedState, enhancer) => {
4+
// shuffle around params if preloadedState is null
5+
if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') {
6+
enhancer = preloadedState
7+
preloadedState = undefined
8+
}
9+
10+
// wrap the reducer with one which we can replace
11+
const reducer = reactotron.createReplacementReducer(rootReducer)
12+
13+
// wrap the enhancer with our beginning and ending one
14+
const wrappedEnhancer = compose(enhancer, reactotron.createActionTracker())
15+
16+
// call the redux create store
17+
const store = createStore(reducer, preloadedState, wrappedEnhancer)
18+
19+
// remember this store
20+
reactotron.setReduxStore(store)
21+
22+
return store
23+
}

Diff for: src/get-subscription-values.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import R from 'ramda'
2+
import RS from 'ramdasauce'
3+
import getCleanedState from './state-cleaner'
4+
5+
// fishes out the values for the subscriptions in state and returns them
6+
export default (subscriptions, state) => {
7+
const cleanedState = getCleanedState(state)
8+
9+
return R.pipe(
10+
R.map(R.when(R.isNil, R.always(''))),
11+
R.filter(RS.endsWith('.*')),
12+
R.map(key => {
13+
const keyMinusWildcard = R.slice(0, -2, key)
14+
const value = RS.dotPath(keyMinusWildcard, cleanedState)
15+
if (R.is(Object, value) && !RS.isNilOrEmpty(value)) {
16+
return R.pipe(R.keys, R.map(key => `${keyMinusWildcard}.${key}`))(value)
17+
}
18+
return []
19+
}),
20+
R.concat(R.map(R.when(R.isNil, R.always('')), subscriptions)),
21+
R.flatten,
22+
R.reject(RS.endsWith('.*')),
23+
R.uniq,
24+
R.sortBy(R.identity),
25+
R.map(key => ({
26+
path: key,
27+
value: RS.isNilOrEmpty(key) ? cleanedState : RS.dotPath(key, cleanedState)
28+
}))
29+
)(subscriptions)
30+
}

0 commit comments

Comments
 (0)