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

wip: add support for lazily replacing variables #1388

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Pranav2612000
Copy link
Contributor

No description provided.

// convert the variables to a substitutor object (will not reconvert if already substitutor)
variables = Substitutor.box(variables, Substitutor.DEFAULT_VARS);

const promises = [];
Copy link
Contributor Author

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);
Copy link
Contributor Author

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.

@Pranav2612000 Pranav2612000 force-pushed the feat/add-support-for-lazy-replacer branch from 7d554c9 to 9507de0 Compare November 25, 2024 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant