How to use the penpal/lib/connectToChild function in penpal

To help you get started, we’ve selected a few penpal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github weseek / growi / src / client / js / components / PageEditorByHackmd / HackmdEditor.jsx View on Github external
initHackmdWithPenpal() {
    const _this = this; // for in methods scope

    const iframe = document.createElement('iframe');
    iframe.src = `${this.props.hackmdUri}/${this.props.pageIdOnHackmd}?both`;
    this.iframeContainer.appendChild(iframe);

    const connection = connectToChild({
      iframe,
      methods: { // expose methods to HackMD
        notifyBodyChanges(document) {
          _this.notifyBodyChangesHandler(document);
        },
        saveWithShortcut(document) {
          _this.saveWithShortcutHandler(document);
        },
      },
      debug: DEBUG_PENPAL,
    });
    connection.promise.then((child) => {
      this.hackmd = child;
      if (this.props.initializationMarkdown != null) {
        child.setValueOnInit(this.props.initializationMarkdown);
      }

penpal

A promise-based library for communicating with iframes via postMessage.

MIT
Latest version published 3 years ago

Package Health Score

56 / 100
Full package analysis