Skip to content
This repository was archived by the owner on Aug 8, 2020. It is now read-only.

Add a symbol property to get current option chain's option #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict';
const optsSymbol = Symbol('option-chain-opts');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const optsSymbol = Symbol('option-chain-opts');
const optionsSymbol = Symbol('optionChainOptions');


module.exports = (options, fn, target) => {
const chainables = options.chainableMethods || {};
const spread = options.spread;
Expand All @@ -14,6 +16,13 @@ module.exports = (options, fn, target) => {
}
});
}
Object.defineProperty(target, optsSymbol, {
enumerable: true,
configurable: true,
get() {
return getter();
}
});
}

function wrap(createOpts, extensionOpts, ctx) {
Expand Down Expand Up @@ -53,3 +62,5 @@ module.exports = (options, fn, target) => {

return wrap(copyDefaults);
};

module.exports.optsSymbol = optsSymbol;
12 changes: 12 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,15 @@ test('spread option spreads arguments', t => {
t.deepEqual(def('a', 'b'), [{}, 'a', 'b']);
t.deepEqual(def.foo('c', 'd'), [{foo: true}, 'c', 'd']);
});

test('access opts with opts symbol', t => {
const def = fn({
chainableMethods: {
foo: {foo: true}
}
}, () => {

});

t.deepEqual(def.foo[fn.optsSymbol], {foo: true});
});