Skip to content

Instantly share code, notes, and snippets.

View VineetKumarKushwaha's full-sized avatar

vineet kumar VineetKumarKushwaha

View GitHub Profile
@VineetKumarKushwaha
VineetKumarKushwaha / .eslintrc
Last active July 5, 2020 13:09
Typescript configuration for node Js with eslint and prettierrc
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"settings": {
"import/resolver": {
"typescript": {} // this loads <rootdir>/tsconfig.json to eslint
}
@VineetKumarKushwaha
VineetKumarKushwaha / Publisher-Subscriber.js
Created July 3, 2020 11:49
Publisher-Subscriber Pattern
const pubSub = (() => {
const topicSubscriberMap = new Map();
const throwError = (topic) => {
throw new Error(`
No ${topic} named topic found in the registry.
Available topics:- ${JSON.stringify(getAllTopic())}
`);
};
const getAllTopic = () => Array.from(topicSubscriberMap.keys());
@VineetKumarKushwaha
VineetKumarKushwaha / Index.js
Last active June 27, 2020 18:02
React Context Provider Pattern
import React from "react";
import { useUser, UserProvider } from "./user-context";
const Address = () => {
const {
state: {
user: { address }
}
} = useUser();
return (
@VineetKumarKushwaha
VineetKumarKushwaha / Observer.js
Last active June 27, 2020 09:21
Observer pattern
const makeObservable = (fn) => {
const observers = new Map();
const register = (observer) => observers.set(observer, observer);
const deRegister = (observer) => observers.delete(observer)
const notify = (value) => observers.forEach(observer => observer && observer(value));
fn(notify);
return { register, deRegister };
}