kfix/MacPin

refactor JS API

kfix opened this issue · 12 comments

kfix commented

Most of the API surface I want to use & support is now exposed, but its a bit clunky.

delegate:

  • should take advantage of ES6 classes so that one can initialize an App object from a class constructor and return that. Then ESlint can check for oopsies and IDEs can do code completion.
    • delegate.{someNamedScriptMessageHandler} -> App().messageHandlers.{someName}(webview,...msg)
    • delegate.launchURL(str) -> App().selectors.launch(...arguments)
    • delegate.decideNavigationFoo(urlstr) -> App().webviewHooks.navigationFoo(webview, url)
      • ideally, one could attach hooks to specific web views from JS

$ is also vague and intones jQuery.

  • export a MacPin singleton?
    • $.app -> MacPin.os, MacPin.process, MacPin.bundle
    • $.browser -> MacPin.window
    • $.browser.tabs -> MacPin.webviews
kfix commented

extend and JSExport NSURL()s as URL(), behaving roughly like the URL() in most browser DOMs. That would standardize all the delegate methods and launch()

JS polyfills:

kfix commented

this could be handy for aliasing some exported methods:
https://gist.github.com/zeitiger/1387f7d996f64b493608

kfix commented

support fetch API instead of XMLHttpRequest??

kfix commented

another URI lib: https://github.com/medialize/URI.js
Consider including SystemJS/jspm, and allowing module loads before MacPin API is extended in.

kfix commented

a good listing of available JS features: https://webkit.org/status/

kfix commented

Chrome's chrome.tabs API is not synchronous at all.
Safari's is but doesn't support .push()ing a tab.

Both fire events for tab actions.

kfix commented

rather than app.js having to explicitly return an object that will become the jsdelegate, this should just be that object.

kfix commented

Firefox is going to support a majority of Chrome's API as 'chrome.'

https://github.com/mdn/webextensions-examples

kfix commented

expose NSUserDefaults to app.js as localStorage()

kfix commented

URL() is being added to WebCore (yay!) hopefully for Safari 10
macgap: https://github.com/MacGapProject/MacGap1/wiki/API-Reference

kfix commented

nodejs APIs can be shimmed in:
https://github.com/nodekit-io/nodekit-darwin