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

Support widget setters as they are in flutter framework #620

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

anserwaseem
Copy link
Contributor

Describe your changes

Screenshots [Optional]

Issue ticket number and link

Closes #619

Checklist before requesting a review

  • I have performed a self-review of my code
  • I have added tests
  • I have added a changeset pnpm changeset add
  • I have added example usage in the kitchen sink app

@anserwaseem anserwaseem self-assigned this May 27, 2024
Copy link

changeset-bot bot commented May 27, 2024

🦋 Changeset detected

Latest commit: b6e048e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@ensembleui/react-framework Patch
@ensembleui/react-kitchen-sink Patch
@ensembleui/react-preview Patch
@ensembleui/react-starter Patch

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

Copy link
Contributor

github-actions bot commented May 27, 2024

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

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

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...

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.

Support widget setters for flutter compatibility
2 participants