Skip to content

Instantly share code, notes, and snippets.

View ShMcK's full-sized avatar

Shawn McKay ShMcK

View GitHub Profile
@ShMcK
ShMcK / branch-expo.js
Created March 10, 2018 21:01
Branch Expo
import { DangerZone } from 'expo'
const { Branch } = DangerZone
Branch.subscribe((bundle) => {
if (bundle && bundle.params && !bundle.error) {
// handle link
}
})
@ShMcK
ShMcK / branch-server.js
Created March 10, 2018 20:58
branch server
class DeepLink {
constructor(branchKey) {
this.key = branchKey;
this.url = 'https://api.branch.io/v1/url';
}
request(data) {
return fetch(this.url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@ShMcK
ShMcK / expo-message-server.js
Created March 10, 2018 20:34
simple expo message server demo
const Expo = require('expo-server-sdk')
const expo = new Expo()
async function send(messages) {
const chunks = expo.chunkPushNotifications(messages)
for (const chunk of chunks) {
try {
const receipts = await expo.sendPushNotificationsAsync(chunk)
receipts.forEach(receipt => {
if (receipt.status === 'error') {
@ShMcK
ShMcK / expo-pn-listener.js
Last active March 10, 2018 20:28
expo-pn-listener
import { Notifications } from 'expo'
Notifications.addListener(async ({ data, origin }) => {
if (origin === 'received') {
// trigger modal
} else if (origin === 'selected') {
// route to page with linked data
}
})
@ShMcK
ShMcK / twilio-wrapper.js
Created March 10, 2018 19:29
twilio-wrapper.js
const twilio = require('twilio');
// created in order to stub twilio in tests
module.exports = {
init: () => twilio(ACCOUNT_ID, AUTH_TOKEN).messages,
};
@ShMcK
ShMcK / twilio-multiple.js
Last active March 10, 2018 19:27
twilio-multiple.js
const twilio = require('./utils/twilio');
class TwilioSMS {
constructor(messagingServiceSid, account) {
this.from = messagingServiceSid;
this.sms = twilio.init(account);
this.sendSMS = ({ to, body }) => this.sms.create({ to, body, messagingServiceSid: this.from });
this.attempts = 0;
}
send(to, body) {
@ShMcK
ShMcK / rematch-outline.js
Last active February 26, 2018 15:51
Rematch outline
import { init, dispatch } from '@rematch/core'
import delay from './makeMeWait.js'
const count = {
state: 0,
reducers: {
increment: (state, payload) => state + payload,
decrement: (state, payload) => state - payload,
},
effects: {
@ShMcK
ShMcK / action-creator.js
Last active February 26, 2018 15:44
Consistent Action Creator
const anyActionCreator = (namespace, type) => (payload) => ({
type: `${namespace}/${type}`,
payload
})
@ShMcK
ShMcK / redux-grouping.js
Created February 26, 2018 15:39
Redux grouping
const count = {
state: 0,
reducers: {
increment: (state, action) => state + action.payload,
decrement: (state, action) => state - action.payload,
}
}
@ShMcK
ShMcK / thunkless-async.js
Created February 26, 2018 15:38
thunkless async
const incrementAsync = async (count) => {
await delay()
dispatch(increment(count))
}