wip: add support for lazily replacing variables - #1388
Draft
Pranav2612000 wants to merge 1 commit into
Draft
Pranav2612000 wants to merge 1 commit into
Pranav2612000 wants to merge 1 commit into
Conversation
Pranav2612000
force-pushed
the
feat/add-support-for-lazy-replacer
branch
from
November 25, 2024 05:54
1770756 to
2219c42
Compare
Pranav2612000
commented
Nov 25, 2024
Pranav2612000
commented
Nov 25, 2024
| _.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); |
Contributor
Author
There was a problem hiding this comment.
@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
Promisevalues. 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
force-pushed
the
feat/add-support-for-lazy-replacer
branch
from
November 25, 2024 07:01
7d554c9 to
9507de0
Compare
Pranav2612000
force-pushed
the
feat/add-support-for-lazy-replacer
branch
2 times, most recently
from
January 15, 2025 14:49
a2042c1 to
8873d7f
Compare
Pranav2612000
force-pushed
the
feat/add-support-for-lazy-replacer
branch
from
January 15, 2025 14:51
8873d7f to
46fac10
Compare
Pranav2612000
commented
Jan 16, 2025
Comment on lines
+86
to
+99
| let index = 0, | ||
| match; | ||
|
|
||
| while ((match = regex.exec(this.value.slice(index)))) { | ||
| try { | ||
| // eslint-disable-next-line no-await-in-loop | ||
| let value = await replacerFn(...match); | ||
|
|
||
| index += match.index; | ||
| this.value = this.value.slice(0, index) + value + this.value.slice(index + match[0].length); | ||
| index += match[0].length; | ||
| } | ||
| catch (_err) { /* empty */ } | ||
| } |
Contributor
Author
There was a problem hiding this comment.
custom string replace logic instead of using String.replace ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace ) as it does not support async replacer fn
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.