-
Notifications
You must be signed in to change notification settings - Fork 221
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
wip: add support for lazily replacing variables #1388
base: develop
Are you sure you want to change the base?
wip: add support for lazily replacing variables #1388
Conversation
1770756
to
2219c42
Compare
// convert the variables to a substitutor object (will not reconvert if already substitutor) | ||
variables = Substitutor.box(variables, Substitutor.DEFAULT_VARS); | ||
|
||
const promises = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@appurva21 Thoughts on supporting async updates this way? This feels weird but I didn't want to touch the _.mergeWith
and customizer
fns. Or do you think it's okay if we write a custom implementation for mergeWith
which supports async replaces ?
@@ -208,6 +222,7 @@ _.assign(Variable.prototype, /** @lends Variable.prototype */ { | |||
_.has(options, 'system') && (this.system = options.system); | |||
_.has(options, 'disabled') && (this.disabled = options.disabled); | |||
_.has(options, 'description') && (this.describe(options.description)); | |||
_.has(options, 'lazy') && (this.lazy = options.lazy); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@appurva21 Thoughts on this approach?
The advantage is that it makes it clear which variables are to be resolved lazily, and which are to be replaced immediately. The disadvantage is that lazy
has no meaning for replaceSubstitutions
( non lazy ), and makes the replaceSubstitutionsLazy
interface more complicated.
Some other approaches I thought about
- A) lazily replace all values ( when invoked through
replaceSubstitutionsLazy
) but this increases the amount of memory needed, and slightly slows down the function. - B) Only lazily replace
Promise
values. This is a good solution but there is no reliable method of identifying if something is a promise or not. ( Duck typing is not accurate ) - C) Only lazily replace function values. Could be a good tradeoff but has the same problems as (A), also makes the code slightly less intuitive.
7d554c9
to
9507de0
Compare
No description provided.