Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed proxyContextEs5 name to proxylessContext, fixed addRuleSet bug #1

Open
wants to merge 2 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

- Bug with environments that cannot use the Proxy object ([#45](https://github.com/imbrn/v8n/issues/45))

### Fixed

- Bug with schema validation ([#166](https://github.com/imbrn/v8n/pull/166))

## [1.3.3] - 2019-09-15
Expand Down
2 changes: 1 addition & 1 deletion docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sidebar: auto

- **Signature:** `v8n()`

- **Returns:** `Proxy`
- **Returns:** `Proxy` or `Object` in environments where `Proxy` is unavailable.

- **Usage:**

Expand Down
12 changes: 7 additions & 5 deletions src/v8n.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Context from "./Context";
function v8n() {
return typeof Proxy !== "undefined"
? proxyContext(new Context())
: proxyContextEs5(new Context());
: proxylessContext(new Context());
}

// Custom rules
Expand Down Expand Up @@ -39,18 +39,20 @@ function proxyContext(context) {
});
}

function proxyContextEs5(context) {
const addRuleSet = (ruleSet, targetContext) =>
function proxylessContext(context) {
const addRuleSet = (ruleSet, targetContext) => {
Object.keys(ruleSet).forEach(prop => {
targetContext[prop] = (...args) => {
const newContext = proxyContextEs5(targetContext._clone());
const newContext = proxylessContext(targetContext._clone());
const contextWithRuleApplied = newContext._applyRule(
ruleSet[prop],
prop
)(...args);
return contextWithRuleApplied;
};
});
return targetContext;
};

const contextWithAvailableRules = addRuleSet(availableRules, context);
const contextWithAllRules = addRuleSet(
Expand All @@ -61,7 +63,7 @@ function proxyContextEs5(context) {
Object.keys(availableModifiers).forEach(prop => {
Object.defineProperty(contextWithAllRules, prop, {
get: () => {
const newContext = proxyContextEs5(contextWithAllRules._clone());
const newContext = proxylessContext(contextWithAllRules._clone());
return newContext._applyModifier(availableModifiers[prop], prop);
}
});
Expand Down