Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: add getExtensions method to extend zoid component instance #468

Merged
merged 6 commits into from
Dec 19, 2024

Conversation

ravishekhar
Copy link
Contributor

  • We have a use case where its necessary to add support for additional methods on the Zoid component instance.
  • To support this use case getExtensions callback is being added to create method.
  • Zoid would call this method to add the additional properties returned by this callback on the component instances.
  • This method will accept the parent props as an argument so that the extended methods could interact with props passed during initialization.
  • The implementation will ensure that getExtensions cannot override any of the existing methods in Zoid like render, clone etc.

Sample usage

const MyComponent = zoid.create({
    tag: "custom-buttons",
    getExtensions: (parent) => {
     // methods defined in parent props, like `onCancel` will be available in 
     // props returned by parent.getProps();
      return {
        hasReturned: () => true,
        resume: () => {
          console.log("Resuming ....");
        },
      };
    }
});

const component = MyComponent({ 
     onCancel: function() { ... }
})

Now the component instance will contain the additional methods along with standard methods.
e.g.

component.hasReturned(); // will return true
component.resume(); // will log Resuming .... on console. 

@ravishekhar ravishekhar requested a review from a team as a code owner December 18, 2024 22:18
@ravishekhar ravishekhar merged commit 44d2d24 into main Dec 19, 2024
2 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants