Skip to content

Commit

Permalink
V0.0.2: new api and unsubscribe callbacks (#4)
Browse files Browse the repository at this point in the history
* v0.0.2 - re-write API

* v0.0.2 - update readme

* v0.0.2: return unsubscribe callbacks

* v0.0.2 - document new unsubscribe cb

* v0.0.2 - bump circle ci node version for Promise availability

* v0.0.2: fix eslint prettier integration

* v0.0.2: fix unsubscribe types

* v0.0.2: no longer need to initialize the middlewares on each apply middleware call

* v0.0.2 - wip

* v0.0.2: better tests

* v0.0.2: 100% code cov

* v0.0.2: 100%?
  • Loading branch information
Ricardo-Marques authored Apr 30, 2018
1 parent e44a278 commit 7e7cfd3
Show file tree
Hide file tree
Showing 24 changed files with 1,363 additions and 489 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:7.10
- image: circleci/node:9.6.1

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
Expand Down
30 changes: 12 additions & 18 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
{
"parser": "babel-eslint",
"extends": [
"eslint:recommended",
"plugin:flowtype/recommended"
"plugin:flowtype/recommended",
"prettier",
"prettier/flowtype",
],
"plugins": [
"flowtype",
"prettier",
],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"experimentalObjectRestSpread": true
},
"sourceType": "module"
},
"env": {
"browser": true,
"jest": true,
"node": true
"es6": true,
"node": true,
"jest": true
},
"plugins": [
"eslint-plugin-flowtype"
],
"rules": {
"key-spacing" : 0,
"max-len" : [2, 120, 4],
"object-curly-spacing" : [2, "always"],
"indent" : [2, 2]
"prettier/prettier": "error"
}
}
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
printWidth: 80
semi: false
singleQuote: true
parser: flow
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,23 @@ export default UserFetcher
```javascript
import UserFetcher from 'fetchers/User'
// every time the UserFetcher successfully resolves, fire this callback
// args will be an array of the arguments provided when we call "execute" and res will be whatever the promise
// args will be an array of the arguments provided when we call "request" and res will be whatever the promise
// originally given to the PromiseMiddleware resolved with
UserFetcher.applyOnSuccessMiddleware(({ res, args }) => onUserFetchSuccess(res, idGetter(...args)))
// returns a callback to unsubscribe the middleware
const unsubscribe = UserFetcher.onSuccess(({ res, args }) => onUserFetchSuccess(res, idGetter(...args)))

function onUserFetchSuccess (user, id) {
console.log(`Got the user with the id ${id}!`, user)
function onUserFetchSuccess({ res }) {
console.log(`Got the user with the id ${id}!`, res)
}

UserFetcher.execute(1)
UserFetcher.execute(1) // does not call the server because we are deduping requests to the same user
UserFetcher.execute(2)
UserFetcher.request(1)
UserFetcher.request(1) // does not call the server because we are deduping requests to the same user
UserFetcher.request(2)

// ...sometime later
UserFetcher.execute(2) // does not call the server because we applied a cache to this fetcher
UserFetcher.request(2) // does not call the server because we applied a cache to this fetcher
unsubscribe() // when we no longer care about request events, we can unsubscribe to avoid memory leaks
//
```

## Publishing
Expand Down
143 changes: 143 additions & 0 deletions flow-typed/npm/coveralls_vx.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// flow-typed signature: b3ed6e5662dc01278d39b578f72efbf6
// flow-typed version: <<STUB>>/coveralls_v^3.0.0/flow_v0.71.0

/**
* This is an autogenerated libdef stub for:
*
* 'coveralls'
*
* Fill this stub out by replacing all the `any` types.
*
* Once filled out, we encourage you to share your work with the
* community by sending a pull request to:
* https://github.com/flowtype/flow-typed
*/

declare module 'coveralls' {
declare module.exports: any;
}

/**
* We include stubs for each file inside this npm package in case you need to
* require those files directly. Feel free to delete any files that aren't
* needed.
*/
declare module 'coveralls/bin/coveralls' {
declare module.exports: any;
}

declare module 'coveralls/fixtures/lib/index' {
declare module.exports: any;
}

declare module 'coveralls/lib/convertLcovToCoveralls' {
declare module.exports: any;
}

declare module 'coveralls/lib/detectLocalGit' {
declare module.exports: any;
}

declare module 'coveralls/lib/fetchGitData' {
declare module.exports: any;
}

declare module 'coveralls/lib/getOptions' {
declare module.exports: any;
}

declare module 'coveralls/lib/handleInput' {
declare module.exports: any;
}

declare module 'coveralls/lib/logger' {
declare module.exports: any;
}

declare module 'coveralls/lib/sendToCoveralls' {
declare module.exports: any;
}

declare module 'coveralls/test/convertLcovToCoveralls' {
declare module.exports: any;
}

declare module 'coveralls/test/detectLocalGit' {
declare module.exports: any;
}

declare module 'coveralls/test/fetchGitData' {
declare module.exports: any;
}

declare module 'coveralls/test/getOptions' {
declare module.exports: any;
}

declare module 'coveralls/test/handleInput' {
declare module.exports: any;
}

declare module 'coveralls/test/logger' {
declare module.exports: any;
}

declare module 'coveralls/test/sendToCoveralls' {
declare module.exports: any;
}

// Filename aliases
declare module 'coveralls/bin/coveralls.js' {
declare module.exports: $Exports<'coveralls/bin/coveralls'>;
}
declare module 'coveralls/fixtures/lib/index.js' {
declare module.exports: $Exports<'coveralls/fixtures/lib/index'>;
}
declare module 'coveralls/index' {
declare module.exports: $Exports<'coveralls'>;
}
declare module 'coveralls/index.js' {
declare module.exports: $Exports<'coveralls'>;
}
declare module 'coveralls/lib/convertLcovToCoveralls.js' {
declare module.exports: $Exports<'coveralls/lib/convertLcovToCoveralls'>;
}
declare module 'coveralls/lib/detectLocalGit.js' {
declare module.exports: $Exports<'coveralls/lib/detectLocalGit'>;
}
declare module 'coveralls/lib/fetchGitData.js' {
declare module.exports: $Exports<'coveralls/lib/fetchGitData'>;
}
declare module 'coveralls/lib/getOptions.js' {
declare module.exports: $Exports<'coveralls/lib/getOptions'>;
}
declare module 'coveralls/lib/handleInput.js' {
declare module.exports: $Exports<'coveralls/lib/handleInput'>;
}
declare module 'coveralls/lib/logger.js' {
declare module.exports: $Exports<'coveralls/lib/logger'>;
}
declare module 'coveralls/lib/sendToCoveralls.js' {
declare module.exports: $Exports<'coveralls/lib/sendToCoveralls'>;
}
declare module 'coveralls/test/convertLcovToCoveralls.js' {
declare module.exports: $Exports<'coveralls/test/convertLcovToCoveralls'>;
}
declare module 'coveralls/test/detectLocalGit.js' {
declare module.exports: $Exports<'coveralls/test/detectLocalGit'>;
}
declare module 'coveralls/test/fetchGitData.js' {
declare module.exports: $Exports<'coveralls/test/fetchGitData'>;
}
declare module 'coveralls/test/getOptions.js' {
declare module.exports: $Exports<'coveralls/test/getOptions'>;
}
declare module 'coveralls/test/handleInput.js' {
declare module.exports: $Exports<'coveralls/test/handleInput'>;
}
declare module 'coveralls/test/logger.js' {
declare module.exports: $Exports<'coveralls/test/logger'>;
}
declare module 'coveralls/test/sendToCoveralls.js' {
declare module.exports: $Exports<'coveralls/test/sendToCoveralls'>;
}
Loading

0 comments on commit 7e7cfd3

Please sign in to comment.