refactor JS API
kfix opened this issue · 12 comments
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
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:
this could be handy for aliasing some exported methods:
https://gist.github.com/zeitiger/1387f7d996f64b493608
Its possible to renamed exported vars/funcs with @objc(betterJSName:) and exclude overloads with @nonobjc
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html#//apple_ref/doc/uid/TP40014216-CH4-ID55
another URI lib: https://github.com/medialize/URI.js
Consider including SystemJS/jspm, and allowing module loads before MacPin API is extended in.
a good listing of available JS features: https://webkit.org/status/
rather than app.js having to explicitly return an object that will become the jsdelegate, this
should just be that object.
Firefox is going to support a majority of Chrome's API as 'chrome.'
expose NSUserDefaults to app.js as localStorage()
URL() is being added to WebCore (yay!) hopefully for Safari 10
macgap
: https://github.com/MacGapProject/MacGap1/wiki/API-Reference
nodejs APIs can be shimmed in:
https://github.com/nodekit-io/nodekit-darwin