Skip to content

Instantly share code, notes, and snippets.

View aem's full-sized avatar

Adam Markon aem

View GitHub Profile
/*
An installer is a package that has a single index.(ts|js) file with a single
default export. Its type is
class Installer<Options extends InstallerOptions> {
steps: InstallerStep[]
options: Options
}
export const LazyValueState = Record(
{
promise: null,
value: LOADING,
},
'LazyValueState'
);
function usePrevious(value) {
const prevRef = useRef();
useEffect(() => {
prevRef.current = value;
}, [value]);
return prevRef.current;
}
function Player({ online, playbackStatus, reload }) {
const prevOnline = usePrevious(online);
@aem
aem / DaggerModule.kt
Last active December 30, 2019 19:15
HubSpot React Native Architecture
// Inside of a Dagger module
@Singleton
@Provides
fun provideReactInstanceManager(context: Context): ReactInstanceManager {
return ReactInstanceManager.builder()
.setApplication(HubspotOneApp.get(context))
.addPackage(MainReactPackage())
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(BEFORE_RESUME)
.setJSMainModuleName("index.android")
class ReactResultRouter(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
@Inject lateinit var reactEventDispatcher: ReactEventDispatcher
init {
HubspotOneApp.get(reactContext.baseContext).component().inject(this)
}
override fun getName(): String = "ReactResultRouter"
@Singleton
class ReactEventDispatcher @Inject constructor(val reactInstanceManager: ReactInstanceManager) {
private val callResults = PublishSubject<ReadableMap>()
private var currentKey: Long = 0L
private fun nextKey(): Long {
currentKey += 1
return currentKey
}
import React from 'react'
import { DeviceEventEmitter, NativeModules } from 'react-native'
const addListener = (event, callback) => {
DeviceEventEmitter.addListener(event, ({key, data}) => {
// `key` is the numeric key assigned by the native dispatcher,
// `data` contains the data that the native call actually wanted to pass
NativeModules.ReactResultRouter.routeResults({
key,
data: callback(data)
// Inside of a Dagger module
@Singleton
@Provides
fun provideReactInstanceManager(context: Context): ReactInstanceManager {
return ReactInstanceManager.builder()
.setApplication(HubspotOneApp.get(context))
.addPackage(MainReactPackage())
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(BEFORE_RESUME)
.setJSMainModuleName("index.android")
module.exports = {
config: {
// default font size in pixels for all tabs
fontSize: 14,
// font family with optional fallbacks
fontFamily: 'Menlo, "DejaVu Sans Mono", "Lucida Console", monospace',
// terminal cursor background color and opacity (hex, rgb, hsl, hsv, hwb or cmyk)
cursorColor: 'rgba(248,28,229,0.8)',
import java.awt.Color;
import javalib.funworld.World;
import javalib.worldimages.OverlayImages;
import javalib.worldimages.Posn;
import javalib.worldimages.RectangleImage;
import javalib.worldimages.TextImage;
import javalib.worldimages.WorldEnd;
import javalib.worldimages.WorldImage;