Skip to content

Instantly share code, notes, and snippets.

View sandwichsudo's full-sized avatar

Gilly Ames sandwichsudo

View GitHub Profile
@sandwichsudo
sandwichsudo / machine.js
Created August 13, 2021 11:56
Generated by XState Viz: https://xstate.js.org/viz
const machine = Machine(
{
id: 'call',
context: {
participants: [],
color: '#fff',
},
initial: 'idle',
states: {
idle: {
@sandwichsudo
sandwichsudo / machine.js
Last active July 30, 2021 14:54
Generated by XState Viz: https://xstate.js.org/viz
const door = Machine({
id: 'door',
initial: 'idle',
states: {
idle: {
context: {
participants: [],
},
@sandwichsudo
sandwichsudo / InfiniteScroll.jsx
Last active July 16, 2019 14:30
React Infinite scroll component (design for use with ApolloClient/Relay Pagination)
/**
* Credit: https://medium.com/@alfianlosari/graphql-cursor-infinite-scroll-pagination-with-react-apollo-client-and-github-api-fafbc510b667
* This component will call the onLoadMore prop when you scroll to the bottom of the page or click
* the button, and pass the fetched data to the component you give it
* */
import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
class InfiniteScroll extends Component {
@sandwichsudo
sandwichsudo / SearchService.spec.js
Last active July 27, 2017 14:50
Search Service Specification
// src/services/search/searchService.spec.js
import searchService from './searchService';
import xhr from '../../xhr/xhr';
// requests the mocked version of the xhr module
jest.mock('../../xhr/xhr');
describe('search service', () => {
describe('repoSearch', () => {
@sandwichsudo
sandwichsudo / RepoSearchActions.spec.js
Last active July 27, 2017 14:44
Test for RepoSearchActions
// src/containers/RepoSearchPage/actions/RepoSearchActions.spec.js
import { fetchRepos } from './RepoSearchActions';
import searchService from '../../../services/search/searchService';
jest.mock('../../../services/search/searchService');
describe('repo search actions', () => {
describe('fetchRepos', () => {
it('should call searchService.repoSearch', async () => {
@sandwichsudo
sandwichsudo / searchService.js
Last active July 27, 2017 14:38
Search service implementation
// src/services/search/searchService.js
import xhr from '../../xhr/xhr';
const repoSearch = async () => {
const { data } = await xhr._get('/search/repositories?q=language:javascript&sort=stars&order=desc');
return data;
};
export default {
@sandwichsudo
sandwichsudo / RepoSearchActions.js
Last active July 27, 2017 14:37
Repo Search Action which calls service
// src/containers/RepoSearchPage/actions/RepoSearchActions.js
import searchService from '../../../services/search/searchService';
export const fetchRepos = () => async (dispatch) => {
const { items } = await searchService.repoSearch();
};
@sandwichsudo
sandwichsudo / RepoSearchPage.js
Last active July 27, 2017 14:37
Single page with static content
// src/containers/RepoSearchPage/page/RepoSearchPage.js
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import RepoResultsList from '../components/RepoResultsList/RepoResultsList';
class RepoSearchPage extends Component {
constructor(props) {
super(props);
@sandwichsudo
sandwichsudo / RepoSearchActions.spec.js
Last active July 27, 2017 14:35
Test action is dispatched
// src/containers/RepoSearchPage/actions/RepoSearchActions.spec.js
import { fetchRepos } from './RepoSearchActions';
import searchService from '../../../services/search/searchService';
import { actionTypes } from '../RepoSearchConstants';
jest.mock('../../../services/search/searchService');
describe('repo search actions', () => {
describe('fetchRepos', () => {
@sandwichsudo
sandwichsudo / RepoSearchActions.js
Last active July 27, 2017 14:35
Dispatch action to update the search results
// src/containers/RepoSearchPage/actions/RepoSearchActions.js
import searchService from '../../../services/search/searchService';
import { actionTypes } from '../RepoSearchConstants';
export const fetchRepos = () => async (dispatch) => {
const { items } = await searchService.repoSearch();
dispatch({
type: actionTypes.UPDATE_RESULTS,
items,