Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhallinan committed Oct 4, 2017
1 parent a214ab5 commit 583254b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
19 changes: 6 additions & 13 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ function Counter(opts = {}) {

const withCount = kontext([ `count`, ]);

// pass `kontext` a thunk to gain access to a context setter
const inc = (ctx) => (setCtx) => compose(
// compose generic functions with the context setter to mutate the context
// compose generic functions with the context setter to mutate the context
const inc = (ctx, setCtx) => compose(
setCtx,
setCount,
add(1),
Expand All @@ -65,7 +64,7 @@ const inc = (ctx) => (setCtx) => compose(
Counter.prototype.inc = withCount(inc);

// create reusable logic that isn't coupled to `this`.
const skip = (n, ctx) => (setCtx) => compose(
const skip = (n, ctx, setCtx) => compose(
setCtx,
setCount,
add(n),
Expand Down Expand Up @@ -96,10 +95,10 @@ Type: `Array k`
An array of keys to pick from the function context.


### baseFunction(...*, ctx)
### baseFunction(...*, ctx, setCtx)

The function to lift into the context. The higher-order function appends `ctx` to
the arguments list of `baseFunction`.
The function to lift into the context. The higher-order function appends `ctx`
and `setCtx` to the arguments list of `baseFunction`.

#### ctx

Expand All @@ -111,12 +110,6 @@ value is the value of that key on the function's context. The value of a key
that is not found on the function context is `undefined` on the `ctx` object.
`kontext` binds function values to the context.


### baseFunction(...*, ctx)(setCtx)

If the base function is a thunk, `kontext` will call the inner function with a
context setter.

#### setCtx(props)

Type: `({k: *}) -> {k: *}`
Expand Down
4 changes: 2 additions & 2 deletions src/pick-ctx.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { typeOf, } from './util';

const pickFromCtx = (keys) => (ctx) => keys.reduce((picked, k) => ({
const pickCtx = (keys) => (ctx) => keys.reduce((picked, k) => ({
...picked,
[k]: typeOf(ctx[k]) === `function` ? ctx[k].bind(ctx) : ctx[k],
}), {});

export default pickFromCtx;
export default pickCtx;

0 comments on commit 583254b

Please sign in to comment.