Skip to content

Instantly share code, notes, and snippets.

View etienne-dldc's full-sized avatar

Etienne Dldc etienne-dldc

View GitHub Profile
@etienne-dldc
etienne-dldc / codepad
Last active February 17, 2021 20:13
Codepad
// enter this in your browser then add it as favorite !
data:text/html,<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/><meta http-equiv="X-UA-Compatible" content="ie=edge"/><style>html, body{font-family: 'Fira Code', monospace; margin: 0;} %23container{position: fixed; top: 0; bottom: 0; left: 0; right: 0;}</style> <title>Codepad</title> </head> <body> <div id="container"></div><script src="https://unpkg.com/[email protected]/min/vs/loader.js"></script> <script>require.config({paths:{vs: 'https://unpkg.com/[email protected]/min/vs'}}); require(['vs/editor/editor.main'], function(){function isApplePlatform(){return window && window.navigator && window.navigator.platform ? window.navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i) ? true : false : true;}console.log(monaco.languages.typescript); monaco.languages.typescript.typescriptDefaults.setCompilerOptions({jsx: 'react',}); const fileContent=['function x(){', '\tconso
const secret = Symbol();
type Secret = typeof secret;
type Keys<T> = keyof T;
type NotNeverKeys<T> = { [P in keyof T]: T[P] extends never ? never : P }[keyof T];
type WithoutNever<T> = keyof Pick<T, NotNeverKeys<T>> extends never
? never

Overmind Library author API

Need for modules that can be nested

IMO the main reason we need a way to have nested modules is that it would let us create libraries without forcing the user to put it in a specific module.

Nested module: basic approach

A basic appraoch to nested modules is to simply destrcuturate a module anywhere in state & actions.

@etienne-dldc
etienne-dldc / overmind-resource.ts
Created September 23, 2018 13:55
Experiment about Overmind library api
import App, { derive, hidden, Action, Operation, Mutate } from 'overmind';
declare module 'overmind' {
function hidden<T>(val: T): T;
}
namespace Resource {
enum Status {
Void = 'void',
Pending = 'pending',
@etienne-dldc
etienne-dldc / Hook.js
Created April 4, 2018 12:07
Small class inspired by Tapable
export class Hook {
constructor() {
this.taps = [];
}
call(value) {
return this.taps.reduce((acc, tap) => {
return acc.then(val => {
try {
return tap.fn(val);
@etienne-dldc
etienne-dldc / combineContext.js
Created March 28, 2018 18:38
A small function to combine react Contexts.
import React from 'react';
function onlyChild(children) {
return Array.isArray(children) ? children[0] : children;
}
export function combineContext(contexts) {
class Provider extends React.Component {
render() {
const init = this.props.children;
@etienne-dldc
etienne-dldc / apollo-cache-redux.ts
Created March 13, 2018 18:07
ReduxCache to use redux as Apollo store
import { NormalizedCache, NormalizedCacheObject, StoreObject } from 'apollo-cache-inmemory';
import { Store, Action } from 'redux';
import produce from 'immer';
// SET
const SET = '@apollo/SET';
interface SetAction extends Action {
payload: {
dataId: string;
value: StoreObject;
function detectCircularDependencies(graph) {
let steps = Object.keys(graph).map(v => [v]);
do {
steps = steps.reduce((acc, step) => {
const current = step[step.length - 1];
const init = step[0];
if (step.length > 1 && current === init) {
console.error(`Circular error: ${step.join(' > ')}`)
throw new Error(`Circular error: ${step.join(' > ')}`);
}
@etienne-dldc
etienne-dldc / createStore.js
Created October 19, 2017 07:56
A small redux-like createStore
function createStore(initialState) {
let state = initialState;
const listeners = [];
return {
getState: () => state,
dispatch: (action) => {
state = action(state);
listeners.forEach(listener => listener())
return action;
},
@etienne-dldc
etienne-dldc / 19-react-redux.markdown
Created September 10, 2017 15:01
19 - React Redux