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

How to use repluggable for creating plugins #152

Open
AbolfazlHeidarpour opened this issue May 23, 2021 · 1 comment
Open

How to use repluggable for creating plugins #152

AbolfazlHeidarpour opened this issue May 23, 2021 · 1 comment

Comments

@AbolfazlHeidarpour
Copy link

Hi there
Suppose there is react app. And suppose there are some React feature components, let's say ContactsList, EditContacts, AddContacts. This components must be plugginable. Like how users control and add plugins in WordPress. How this functionality can be implemented with repluggable package?

@itsh01
Copy link
Collaborator

itsh01 commented May 25, 2021

Hi

With a Repluggable package you can extend other Repluggable packages by contributing things (components/objects/functions/...) via their APIs
Internally the owner of those APIs will create extension slots that the React components would consider.
E.g. something like this:

// ContactsAPI.tsx

export interface ContactsAPI {/*...*/}
export const ContactsAPI: SlotKey<ContactsAPI>

interface ContactsExtensionItem {/*...*/}
const contactsExtensionsKey: SlotKey<ContactsExtensionItem> = {
  name: 'contacts-extensions'
}

const ContactListPure: ReactComponent<ContactListProps> = ({extensions}) => <div>{/*...*/}<div/>

const createContactsListComponent = (boundShell: Shell) => connectWithShell(
  shell => ({
    extensions: shell.getSlot(contactsExtensionsKey).getItems()
  }),
  () => ({}),
  boundShell
)(ContactListPure)

export const createContactsAPI = (shell: Shell): ContactsAPI => {
  const contactsExtensions = shell.declareSlot(contactsExtensionsKey)

  return {
    contributeContactExtension(contributingShell: Shell, extension: ContactsExtensionItem) {
      contactsExtensions.contribute(contributingShell, extension)
    },
    ContectsList: createContactsListComponent(shell)
  }
}

// ContactsPackage.tsx

export const contactsPackage: EntryPoint[] = [{
  //...
  attach(shell) { shell.contributeAPI(ContactsAPI, () => createContactsAPI(shell)) },
  extend(shell) {
    const { ContactsList } = shell.getAPI(ContactsAPI)
    shell.getAPI(MyWorkspace).contributeComponent(<ContactsList />)
  }
}]

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

No branches or pull requests

2 participants