Skip to content

Instantly share code, notes, and snippets.

Avatar

Eloy Durán alloy

View GitHub Profile
@alloy
alloy / LiveQueryPolyfill.ts
Last active Jun 13, 2020
Rewrite GraphQL Live Query to subscription.
View LiveQueryPolyfill.ts
/**
* This is a Live Query polyfill, as graphql-js does not strictly have support for that. Instead, we leave it up to the
* client to recognize a Live Query is requested with the `@live` directive on a `query` operation and here we
* transform it into a `live` subscription instead.
*
* Consider a schema like the following:
*
* ```graphql
type Badge {
id: ID!
View 1 - schema.graphql
scalar Date
type Query {
badge: Badge!
}
type Badge {
key: BadgeKey!
text: String!
history: BadgeHistoryConnection!
View glob.json
[
"Apps/Artist/ArtistApp.tsx",
"Apps/Artist/Components/ArtistCollectionsRail/ArtistCollectionEntity.tsx",
"Apps/Artist/Components/ArtistCollectionsRail/ArtistCollectionsRail.tsx",
"Apps/Artist/Components/ArtistCollectionsRail/__tests__/ArtistCollectionEntity.test.tsx",
"Apps/Artist/Components/ArtistCollectionsRail/__tests__/ArtistCollectionsRail.test.tsx",
"Apps/Artist/Components/ArtistCollectionsRail/index.tsx",
"Apps/Artist/Components/ArtistConsignButton.tsx",
"Apps/Artist/Components/ArtistHeader.tsx",
"Apps/Artist/Components/ArtistIndicator.tsx",
@alloy
alloy / build-settings.rb
Created Apr 28, 2020
Example of ways to introspect Xcode build settings
View build-settings.rb
# gem install xcodeproj claide hashdiff
require 'xcodeproj'
require 'claide'
require 'pp'
argv = CLAide::ARGV.new(ARGV)
project_path = argv.shift_argument
target_name = argv.option("target")
target_type = argv.option("target-type", "PBXNativeTarget")
View dump-target-build-settings.rb
require 'xcodeproj'
require 'pp'
unless (project_path = ARGV[0]) && (target_name = ARGV[1])
raise "Usage: ruby #{__FILE__} path/to/the.xcodeproj target-name [diff-base-config]"
end
project = Xcodeproj::Project.open(project_path)
target = project.targets.find { |t| t.name == target_name }
@alloy
alloy / stderr.txt
Last active Feb 28, 2020
v0.62.0-rc.3 CHANGELOG
View stderr.txt
~/C/R/r/releases [changelog-fixes] » yarn generate -b v0.61.5 -c v0.62.0-rc.3 -r ../../react-native -f ./CHANGELOG.md -t [GITHUB-TOKEN]
Resolve base commit
https://github.com/facebook/react-native/commit/bb625e523867d3b8391a76e5aa7c22c081036835
Fetch commit data
https://api.github.com/repos/facebook/react-native/commits?sha=v0.62.0-rc.3&page=1
https://api.github.com/repos/facebook/react-native/commits?sha=v0.62.0-rc.3&page=2
https://api.github.com/repos/facebook/react-native/commits?sha=v0.62.0-rc.3&page=3
https://api.github.com/repos/facebook/react-native/commits?sha=v0.62.0-rc.3&page=4
https://api.github.com/repos/facebook/react-native/commits?sha=v0.62.0-rc.3&page=5
View update-changelog.js
const fs = require("fs");
const PromisePool = require("@supercharge/promise-pool");
const { git, getOriginalCommit } = require("./scripts/changelog-generator");
const gitDir = "/Users/eloy/Code/ReactNative/react-native/.git"
const seen = new Map()
const SHAs = new Set()
const existingChangelogData = fs.readFileSync("./CHANGELOG.md", "utf8");
@alloy
alloy / Podfile
Last active Feb 28, 2020
Example of a Podfile that builds React Native without integrating into an app
View Podfile
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
install! 'cocoapods', :integrate_targets => false
platform :ios, '9.0'
pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
View rn2dts-thoughts.md

In an effort to try to get TypeScript definitions for React Native consistent with the cononical Flow types, I have been looking into the possibility of automating this process.

My initial approach was to see how far I could get without any help needed from Facebook’s side. This process looks something like this:

  1. Transform Flow codebase to TypeScript by leveraging existing tooling with a few additional changes, which mostly replaces Flow utility types with TypeScript ones. (This tooling is presumably meant for people migrating from Flow to TypeScript and thus it is ok for these tools to not deliver perfect conversions.)
  2. Replace $ObjMap usage with a mapped type, as RN’s usage of $ObjMap is trivial (return types are static).
  3. Replace import type {Foo} from "./some-module" with import {Foo} from "./some-module".
  4. Replace `m
@alloy
alloy / 1-input.ts
Last active Feb 17, 2020
Why does TypeScript inline the typeof type?
View 1-input.ts
const x = {
foo: "bar",
answer: 42
}
type X = typeof x
export default {
get X(): X {
return x
You can’t perform that action at this time.