Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Taking a break from OSS

Alexey Kureev Kureev

:octocat:
Taking a break from OSS
View GitHub Profile
@Kureev
Kureev / index.ts
Created Oct 1, 2020
How to initialize Flex with an `errorPage`
View index.ts
Flex
.provideLoginInfo(configuration, "#container")
.then(() => Flex.Manager.create(configuration))
.then(manager => { /* use manager here */ })
.catch(error => Flex.errorPage(error, "#container"));
View parser-part.ts
if (ts.isFunctionTypeNode(typeNode)) {
let argument: Schemify.TypeAnnotation;
this.checker
.getSignaturesOfType(type, ts.SignatureKind.Call)
/**
* At this moment, react-native doesn't support more than one argument
* (Event) passed back from the native side, however the implementation
* I wrote was designed to support multiple parameters (just in case).
*
* That said, I assume the "getParameters" to always return an array
View renderElementOfType2.m
- (void)renderElementOfType:(NSString *)name size:(NSSize)size {
EBWindow *window = [[EBWindow alloc] init];
EBUIManager *manager = [EBUIManager sharedInstance];
[window openWithSize:NSMakeSize((CGFloat)size.width, (CGFloat)size.height)];
NSString *uuid = [[NSUUID UUID] UUIDString];
[manager addValue:window forKey:uuid];
}
View EBUIManager.h
#import <Foundation/Foundation.h>
@interface EBUIManager : NSObject
+ (instancetype)sharedInstance;
- (void)addValue:(id)value forKey:(NSString *)key;
@end
View renderElementOfType.m
- (void)renderElementOfType:(NSString *)name size:(NSSize)size {
GGWindow *window = [[GGWindow alloc] init];
[window openWithSize:NSMakeSize((CGFloat)size.width, (CGFloat)size.height)];
}
View render.cpp
JsValueRef render(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState) {
NSString *type = [NSString stringWithUTF8String:ChakraUtils::toString(arguments[1])];
float w {ChakraUtils::toFloat(arguments[2])};
float h {ChakraUtils::toFloat(arguments[3])};
dispatch_async(dispatch_get_main_queue(), ^{
id delegate = [[NSApplication sharedApplication] delegate];
[delegate renderElementOfType:type size:NSMakeSize((CGFloat)w, (CGFloat)h)];
});
View SetupGlobalEnvironment.js
function SetupGlobalEnvironment() {
var globalObject = JsGetGlobalObject();
var bridge = {
render: render,
};
globalObject.bridge = bridge;
return 0;
}
View SetupGlobalEnvironment.cpp
JsErrorCode SetupGlobalEnvironment() {
JsValueRef globalObject;
JsGetGlobalObject(&globalObject);
JsValueRef bridgeObject;
JsCreateObject(&bridgeObject);
ChakraUtils::setObjectProperty(globalObject, 'bridge', bridgeObject);
ChakraUtils::setObjectFunctionProperty(bridgeObject, 'render', render);
View ChakraProxy+run.m
@implementation ChakraProxy
-(void)run {
unsigned currentSourceContext = 0;
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"main" ofType:@"js"];
NSError *error;
NSString *fileContents = [NSString stringWithContentsOfFile:filepath encoding:NSUTF8StringEncoding error:&error];
if (error) {
View ChakraProxy.h
#import <Foundation/Foundation.h>
@interface ChakraProxy : NSObject
-(void)run;
@end
You can’t perform that action at this time.