-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03a1cd6
commit 993ef9d
Showing
10 changed files
with
158 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,13 @@ | ||
import { Properties as Props } from "protocol"; | ||
import { Context, PropMap } from "./Context"; | ||
import { mapProperties } from "./mapProperties"; | ||
import { normalizeConstant } from "./normalize"; | ||
|
||
export function applyScope<T extends Props>( | ||
scope: PropMap<T>, | ||
props: PropMap<T> | ||
): PropMap<T> { | ||
return Object.setPrototypeOf( | ||
mapProperties( | ||
props, | ||
(prop) => (provided: Context<T>) => | ||
prop(applyScope(normalizeConstant(provided), scope)) | ||
), | ||
mapProperties(props, (prop) => (provided: Context<T>) => prop(scope)), | ||
scope | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
import memo from "memoizee"; | ||
import { Prop } from "./Context"; | ||
import { normalizeConstant } from "./normalize"; | ||
import { normalize } from "./normalize"; | ||
|
||
export const parseToken = memo( | ||
(token: string): Prop<any> => { | ||
const f = Function("$", `return ${token};`); | ||
return (ctx) => | ||
f( | ||
new Proxy(normalizeConstant(ctx), { | ||
get(target, prop: string) { | ||
return target[prop]?.({}); | ||
}, | ||
}) | ||
); | ||
}, | ||
{ primitive: true } | ||
); | ||
export const parseToken = (token: string): Prop<any> => { | ||
const f = Function("$", `return ${token};`); | ||
return (ctx) => | ||
f( | ||
new Proxy(normalize(ctx), { | ||
get(target, prop: string) { | ||
return typeof target?.[prop] === "function" | ||
? target[prop]({}) | ||
: target?.[prop]; | ||
}, | ||
}) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.