Created
October 5, 2018 04:40
-
-
Save danfinlay/4b6c74d0a16da22d5c877ca0e989016e to your computer and use it in GitHub Desktop.
Quick mockup for a simple plugin system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('plugin loaded!') | |
window.parent.postMessage('PLUGIN ping', '*', false) | |
window.addEventListener('message', function (e) { | |
console.log('PLUGIN RECEIVED', e ) | |
window.parent.postMessage('PLUGIN pong', '*', false) | |
}) | |
// A plugin is a function that receives a metamask plugin API: | |
function MetaPlugin (pluginApi) { | |
console.log('calling plugin func!') | |
// A plugin returns an object that adheres to the MetaPlugin protocol: | |
return { | |
// A MetaPlugin includes a getApi() method that returns an API object. | |
getApi() { | |
return { | |
// Let's imagine the protocol requires the API to provide a getName() method. | |
getName() { | |
console.log('sandboxed plugin getting name...') | |
return 'test plugin' | |
} | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment