Rambler.iOS #8 - Make your app extensible with JavaScriptCore

30
Extend Your App With JavaScriptCore Micha MAZAHERI iOS > Mac > Python > React @mittsh

Transcript of Rambler.iOS #8 - Make your app extensible with JavaScriptCore

Page 1: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

Extend Your App With

JavaScriptCoreMicha MAZAHERI

iOS > Mac > Python > React

@mittsh

Page 2: Rambler.iOS #8 - Make your app extensible with JavaScriptCore
Page 3: Rambler.iOS #8 - Make your app extensible with JavaScriptCore
Page 4: Rambler.iOS #8 - Make your app extensible with JavaScriptCore
Page 5: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

API BlueprintIntegration?

Page 6: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

How can we make

Paw hackable with

JavaScriptCore?

Page 7: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

OpenSource

Clean Your App

FocusSmallApps

Page 8: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

Updates

Page 9: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

Updates

Page 10: Rambler.iOS #8 - Make your app extensible with JavaScriptCore
Page 11: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

CocoaScript

Page 12: Rambler.iOS #8 - Make your app extensible with JavaScriptCore
Page 13: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

WebKit

Page 14: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

Your JS API

InterfaceContract

Testing Use itLike it?

Page 15: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

Example

JSContext* context = [[JSContext alloc] init];JSValue* gigaValue = [context evaluateScript:@"Math.pow(2,30)"];NSLog(@"1 GiB = %ld bytes", [gigaValue toNumber].integerValue);// 1 GiB = 1073741824 bytes

Page 16: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

JSValueJavaScript Type Objective-C Type Swift Type

string NSString String

boolean BOOL Bool

number

NSNumberdoubleint32_tuint32_t

NSNumber!DoubleInt32UInt32

Date NSDate Date

Array NSArray [AnyObject]

Object NSDictionary [NSObject : AnyObject]

Object custom type custom type

Page 17: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

JSContext

VirtualMachine

Holds AllObjects

SingleThread

Page 18: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

JSExport

SwiftClass

JavaScriptPrototype

SwiftInstance

JavaScriptObject

Page 19: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

/* Extend JSExport protocol */@protocol LMJSRequest <JSExport>

JSExportAs(getMethod, -(id)method);JSExportAs(getUrl, -(id)url);

JSExportAs(setMethod, -(id)method:(NSString*)method);JSExportAs(setUrl, -(id)url:(NSString*)url);

@end

/* Implement protocol as a category */@interface LMRequest (LMJSRequest) <LMJSRequest>

@end

Page 20: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

Not The Web

DOM WebWorkers Web Crypto

Local Storage

XHR (Ajax)setTimeout

CSSPromiseWebSocket

File API

Page 21: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

Not The Web

Pure Vanilla JS

Page 22: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

Multithreading

Core Data Grand Central

Dispatch

Page 23: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

Run LoopsetTimeout()

DispatchQueue.main.asyncAfter(deadline: time)

…run code…

Page 24: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

Extensions in Paw

ImportersCodeGenerators

DynamicValues

Page 25: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

Code Generators• Client Code (Swift, ObjC, Python, Ruby…)• Command Line (cURL, HTTPie)• API Descriptions (API Blueprint, Swagger, RAML…)• 3rd party (Postman)

Page 26: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

Importers• HTTP Archives (HAR)• API Descriptions (API Blueprint, Swagger, RAML…)• 3rd party (Postman)

Page 27: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

Dynamic Values• Auth (JWT, Digest, Django…)• 3rd party auth (Amazon, Auth0…)• Randomizers (Chance.js, UUID, JSON Schema)

Page 28: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

Who uses JavaScriptCore?

React NativeSafari Build Apps

Page 29: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

Conclusion

• We can open source more• Always have an answer• More features than any competitor• Update extensions multiple times a week

Page 30: Rambler.iOS #8 - Make your app extensible with JavaScriptCore

Thank You

https://paw.cloud@mittsh