Skip to content

Instantly share code, notes, and snippets.

import React, { Component } from 'react'
import io from 'socket.io-client'
import OAuth from './OAuth'
import { API_URL } from './config'
import './App.css'
const socket = io(API_URL)
const providers = ['twitter', 'google', 'facebook', 'github']
export default class App extends Component {
import React, { Component } from 'react'
import FontAwesome from 'react-fontawesome'
import { API_URL } from './config'
export default class OAuth extends Component {
state = {
user: {},
disabled: ''
}
export default class OAuth extends Component {
// previous lifecycle methods
// Routinely checks the popup to re-enable the login button
// if the user closes the popup without authenticating.
checkPopup() {
const check = setInterval(() => {
const { popup } = this
if (!popup || popup.closed || popup.closed === undefined) {
export default class OAuth extends Component {
// previous lifecycle methods
// previous custom methods
render() {
const { name, photo} = this.state.user
const { provider } = this.props
const { disabled } = this.state
const dogs = [
{name: 'Snookums', needsShots: true, breed: 'pug', age: 2},
{name: 'Thor', needsShots: true, breed: 'hound', age: 1},
{name: 'Wunderbar', needsShots: false, breed: 'pug', age: 9},
]
// Lets see how a filter method might work...
const dogsToSeeVet = dogs.myFilter(function(dog) {
Array.prototype.myMap = function(callback) {
const arr = []
for (let i = 0; i < this.length; i++) {
arr.push(callback(this[i], i , this))
}
return arr
}
Array.prototype.myReduce = function(func, initialValue) {
const arr = arguments.length > 1
? [initialValue, ...this]
: this
let accumulator = arr[0]
for (let i = 1; i < arr.length; i++) {
accumulator = func(accumulator, arr[i], i, this)
}
// filter
Array.prototype.myFilter = function(func) {
const arr = []
for (let i = 0; i < this.length; i++) {
const item = this[i]
if(func(item, i, this)) {
arr.push(item)
}
Array.prototype.myFilter = function(callback) {
const arr = []
for (let i = 0; i < this.length; i++) {
const item = this[i]
if(callback(item, i, this)) {
arr.push(item)
}
}
const dogs = [
{name: 'Snookums', needsShots: true, breed: 'pug', age: 2},
{name: 'Thor', needsShots: true, breed: 'hound', age: 1},
{name: 'Wunderbar', needsShots: false, breed: 'pug', age: 9},
]
// We are going to create a new array of our vet approved dogs!
const vetApprovedDogs = dogs.myMap((dog) => {
// The vet makes his approval