Support widget setters as they are in flutter framework#620
Open
anserwaseem wants to merge 3 commits intomainfrom
Open
Support widget setters as they are in flutter framework#620anserwaseem wants to merge 3 commits intomainfrom
anserwaseem wants to merge 3 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: b6e048e The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
Visit the preview URL for this PR (updated for commit b6e048e): https://react-kitchen-sink-dev--pr620-619-support-widget-s-mpwnw38b.web.app (expires Mon, 03 Jun 2024 15:47:11 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 6267897ade2ba783b6db70a53a60fc3946d625e9 |
evshi
reviewed
May 28, 2024
Comment on lines
+41
to
+70
| const modifyJs = ( | ||
| invokables: { [key: string]: InvokableMethods | undefined }, | ||
| js?: string, | ||
| ): string => { | ||
| if (!js || isEmpty(js)) { | ||
| return js || ""; | ||
| } | ||
|
|
||
| // check if the code is assigning a value to a property | ||
| // eslint-disable-next-line prefer-named-capture-group | ||
| const assignmentRegex = /(\w+)\.(\w+)\s*=\s*(.*)$/gm; // matches widgetId.setter = value | ||
| let modifiedCode = js; | ||
|
|
||
| let match; | ||
| while ((match = assignmentRegex.exec(js))) { | ||
| const [fullMatch, widgetId, setter, value] = match; | ||
| const setterName = `set${setter.charAt(0).toUpperCase() + setter.slice(1)}`; | ||
| const originalSetter = invokables[widgetId]?.[setterName]; | ||
|
|
||
| if (originalSetter) { | ||
| // if a setter function exists, replace the assignment with a function call | ||
| modifiedCode = modifiedCode.replace( | ||
| fullMatch, | ||
| `${widgetId}.${setterName}(${value});`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| return modifiedCode; | ||
| }; |
Contributor
There was a problem hiding this comment.
Did you try passing in the state object into the exec context directly? I doubt it would work but might be worth a shot. I think we will need to create some kind of wrapper object that mimics a setter...
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.
Describe your changes
Screenshots [Optional]
Issue ticket number and link
Closes #619
Checklist before requesting a review
pnpm changeset add