Skip to content

Instantly share code, notes, and snippets.

@DroopyTersen
DroopyTersen / machine.js
Last active February 19, 2021 03:43
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// ==UserScript==
// @name SharePoint Rest API Formatter
// @namespace Portals Dev
// @match https://*.sharepoint.com/*_api/*
// @grant none
// @version 1.0
// @author -
// @description 4/19/2020, 2:19:16 PM
// ==/UserScript==
@DroopyTersen
DroopyTersen / machine.js
Last active January 16, 2020 17:26
Generated by XState Viz: https://xstate.js.org/viz
const machine = Machine({
id: 'milkSourceMileageCollection',
initial: 'OPEN',
states: {
OPEN: {
on: {
"sumbit:mileage": "SUBMITTED",
"notify:transfer": 'TRANSFER_NEEDED'
}
},
@DroopyTersen
DroopyTersen / machine.js
Last active January 12, 2020 05:46
Generated by XState Viz: https://xstate.js.org/viz
let _activeIndexingId = "";
let _activeQueryId = "";
const indexingMachine = Machine({
id: 'indexer',
initial: "QUERYING",
states: {
IDLE: {
on: {
PinPoint
Loading*
onload -> Idle
onerror -> Error
Syncing
onload -> Idle
onerror -> Error
Idle
refine -> Loading
refresh -> Syncing
import { useEffect, useState } from "react";
import usePaging from "./usePaging";
import useHover from "./useHover";
import useInterval from "./useInterval";
export default function useAutoPaging(
totalPages: number,
delay = 5000,
defaultPage = 1
) {
@DroopyTersen
DroopyTersen / useHover.ts
Created February 19, 2019 17:35
Composing Behavior with React hooks - useHover
import { useState, useRef, useEffect } from "react";
export default function useHover() {
const [isHovered, setIsHovered] = useState(false);
const hoverRef = useRef(null);
const handleMouseOver = () => setIsHovered(true);
const handleMouseOut = () => setIsHovered(false);
@DroopyTersen
DroopyTersen / useInterval.ts
Last active February 19, 2019 17:25
Composing Behavior with React hooks - useInterval
import { useRef, useEffect } from "react";
export default function useInterval(callback, delay) {
const savedCallback = useRef(null);
useEffect(() => {
savedCallback.current = callback;
});
useEffect(
@DroopyTersen
DroopyTersen / usePaging.ts
Created February 19, 2019 17:17
Composing Behavior with React hooks - usePaging
import { useState } from "react";
export default function usePaging(totalPages: number, defaultPage = 1) {
let [currentPage, setCurrentPage] = useState(defaultPage);
let goBack = () => {
let newPage = currentPage - 1;
if (newPage < 1) newPage = totalPages;
setCurrentPage(newPage);
};
@DroopyTersen
DroopyTersen / NotificationBanner-ClassComponent.tsx
Last active February 19, 2019 16:41
Composing Behavior with React hooks - Class Component baseline
import React from "react";
export default class NotificationBanner extends React.Component {
intervalId = null;
state = {
notifications: [],
isLoading: true,
currentPage: 1
};
componentDidMount() {