Skip to content

Commit

Permalink
Change Fluent API to avoid defining an apply function (with surroun…
Browse files Browse the repository at this point in the history
…ding browser compatibility issues) and improve readability of configuration methods.

In total:
 - .apply(bool) is now .applying(bool)
 - .repeat(bool) is now .repeating(bool)
 - .resolve(bool) is now .resolving(bool)
  • Loading branch information
evan-king committed Aug 12, 2019
1 parent 12b46d1 commit fb6a6fa
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -130,15 +130,15 @@ Get a new immutable Fluent with default `args` provided and `options.apply = tru

Get a new immutable Fluent with default `spec` provided.

#### Fluent.repeat(Boolean) ⇒ Fluent
#### Fluent.repeating(Boolean) ⇒ Fluent

Get a new immutable Fluent with `options.once` reconfigured.

#### Fluent.apply(Boolean) ⇒ Fluent
#### Fluent.applying(Boolean) ⇒ Fluent

Get a new immutable Fluent with `options.apply` reconfigured.

#### Fluent.resolve(Boolean) ⇒ Fluent
#### Fluent.resolving(Boolean) ⇒ Fluent

Get a new immutable Fluent with `options.resolve` reconfigured.

Expand Down
6 changes: 3 additions & 3 deletions index.js
Expand Up @@ -141,9 +141,9 @@
function Fluent(opts) {
opts = opts || {};
return {
repeat: v => Fluent(R.merge(opts, {once: !v})),
apply: v => Fluent(R.merge(opts, {apply: !!v})),
resolve: v => Fluent(R.merge(opts, {resolve: !!v})),
repeating: v => Fluent(R.merge(opts, {once: !v})),
applying: v => Fluent(R.merge(opts, {apply: !!v})),
resolving: v => Fluent(R.merge(opts, {resolve: !!v})),
applyTo: v => Fluent(R.merge(opts, {apply: true, args: v})),
withSpec: v => Fluent(R.merge(opts, {spec: v})),
exec: (spec, args, options) => applySpecP(
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "promise-apply-spec",
"version": "1.0.3",
"version": "2.0.0",
"description": "Reduce a data structure containing promises to a promise of the data structure containing the resolved values.",
"main": "index.js",
"scripts": {
Expand Down
46 changes: 23 additions & 23 deletions test.js
Expand Up @@ -227,8 +227,8 @@ describe('PromiseApplySpec', function() {
const root = applySpecP;

const isFluent = obj => R.map(
key => expect(obj[key]).a('Function'),
['once', 'apply', 'resolve', 'applyTo', 'withSpec']
key => expect(obj[key], key).a('Function'),
['repeating', 'applying', 'resolving', 'applyTo', 'withSpec']
);

it('is available from the default import', () => isFluent(applySpecP));
Expand All @@ -237,7 +237,7 @@ describe('PromiseApplySpec', function() {
expect(root.exec()).eventually.eql(undefined);
});

it('sets once with `options` or .repeat(bool)', tracked(function(track) {
it('sets once with `options` or .repeating(bool)', tracked(function(track) {
const
inner = {b: wrap(1)},
outer = {a: wrap(inner)},
Expand All @@ -247,48 +247,48 @@ describe('PromiseApplySpec', function() {
track(expectResult(full), [
root.exec(outer),
root.exec(outer, null, {once: false}),
root.repeat(true).exec(outer),
root.repeat(false).exec(outer, null, {once: false}),
root.repeating(true).exec(outer),
root.repeating(false).exec(outer, null, {once: false}),
]);

track(expectResult(single), [
root.repeat(false).exec(outer),
root.repeating(false).exec(outer),
root.exec(outer, null, {once: true}),
root.repeat(true).exec(outer, null, {once: true}),
root.repeating(true).exec(outer, null, {once: true}),
]);
}));

it('sets apply with `options` or .apply(bool)', tracked(function(track) {
it('sets apply with `options` or .applying(bool)', tracked(function(track) {
const orig = {a: id}, expanded = {a: 1};

track(expectResult(expanded), [
root.exec(orig, [1]),
root.exec(orig, [1], {apply: true}),
root.apply(true).exec(orig, [1]),
root.apply(false).exec(orig, [1], {apply: true}),
root.applying(true).exec(orig, [1]),
root.applying(false).exec(orig, [1], {apply: true}),
]);

track(expectResult(orig), [
root.exec(orig, [1], {apply: false}),
root.apply(false).exec(orig, [1]),
root.apply(true).exec(orig, [1], {apply: false}),
root.applying(false).exec(orig, [1]),
root.applying(true).exec(orig, [1], {apply: false}),
]);
}));

it('sets resolve with `options` or .resolve(bool)', tracked(function(track) {
it('sets resolve with `options` or .resolving(bool)', tracked(function(track) {
const orig = {a: wrap(1)}, expanded = {a: 1};

track(expectResult(expanded), [
root.exec(orig, [1]),
root.exec(orig, [1], {resolve: true}),
root.resolve(true).exec(orig, [1]),
root.resolve(false).exec(orig, [1], {resolve: true}),
root.resolving(true).exec(orig, [1]),
root.resolving(false).exec(orig, [1], {resolve: true}),
]);

track(expectResult(orig), [
root.exec(orig, [1], {resolve: false}),
root.resolve(false).exec(orig, [1]),
root.resolve(true).exec(orig, [1], {resolve: false}),
root.resolving(false).exec(orig, [1]),
root.resolving(true).exec(orig, [1], {resolve: false}),
].map(v => wrap(v)));
}));

Expand All @@ -299,13 +299,13 @@ describe('PromiseApplySpec', function() {
root.exec(orig, [1]),
root.applyTo([1]).exec(orig),
root.applyTo([2]).exec(orig, [1]),
root.apply(false).applyTo([1]).exec(orig),
root.apply(false).applyTo([3]).exec(orig, [1]),
root.applying(false).applyTo([1]).exec(orig),
root.applying(false).applyTo([3]).exec(orig, [1]),
]);

track(expectResult(orig), [
root.applyTo([1]).apply(false).exec(orig),
root.applyTo([1]).apply(false).exec(orig, [1]),
root.applyTo([1]).applying(false).exec(orig),
root.applyTo([1]).applying(false).exec(orig, [1]),
]);
}));

Expand All @@ -324,7 +324,7 @@ describe('PromiseApplySpec', function() {
const toExpanded = root.withSpec(orig).applyTo([1]);
const toDifferent = toExpanded.applyTo([2]);

toExpanded.withSpec({}).applyTo([3]).apply(false);
toExpanded.withSpec({}).applyTo([3]).applying(false);

track(expectResult(expanded), [toExpanded.exec()]);
track(expectResult(differentArg), [toDifferent.exec()]);
Expand All @@ -336,7 +336,7 @@ describe('PromiseApplySpec', function() {
const root = applySpecP;

const isFP = obj => R.map(
key => expect(obj[key]).a('Function'),
key => expect(obj[key], key).a('Function'),
['all', 'once', 'applySpec', 'unravel', 'unravelOnce']
);

Expand Down

0 comments on commit fb6a6fa

Please sign in to comment.