-
Notifications
You must be signed in to change notification settings - Fork 1
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
Support widget setters as they are in flutter framework #620
base: main
Are you sure you want to change the base?
Support widget setters as they are in flutter framework #620
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 |
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 |
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; | ||
}; |
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.
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...
Describe your changes
Screenshots [Optional]
Issue ticket number and link
Closes #619
Checklist before requesting a review
pnpm changeset add