Skip to content

Instantly share code, notes, and snippets.

😍
Back in OSS business

Mohsen Azimi mohsen1

😍
Back in OSS business
Block or report user

Report or block mohsen1

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View call-site.js
function foo(a) {
console.log(a.b)
}
foo({})
View call-site.js
function power2(a) {
return a * a;
}
power2('string')
View overload.ts
/**
* Create an input element
*/
function createInput(type: 'text', value: string): HTMLInputElement;
function createInput(type: 'checkbox', value: boolean): HTMLInputElement;
function createInput(type, value) {
// code
}
View call-create-input.js
const input = createInput('checkbox', 'false')
View create-input.js
/**
* Create an input element
* @param {string} type
* @param {string|boolean} value
* @return {HTMLInputElement}
*/
function createInput(type, value) {
const el = document.createElement('input');
el.type = type;
if (type === 'checkbox') {
@mohsen1
mohsen1 / HydratableStore.tsx
Created Jul 31, 2017
How to hydrate stores in the server with MobX
View HydratableStore.tsx
import * as React from 'react';
import { computed } from 'mobx';
import { inject, observer, Provider } from 'mobx-react';
import { fromPromise } from 'mobx-utils';
import {StaticRouter} from 'react-router-dom';
import { Request, Response } from 'express';
import * as ReactDOM from 'react-dom/server';
interface Item {
weight: number;
View loadable.ts
import * as React from 'react';
import { RouteComponentProps } from 'react-router-dom';
interface LoadableProps<T> {
loader: (props: RouteComponentProps<T>) => (() => Promise<React.ComponentType<T>> | React.ComponentType<T>);
loading: React.ComponentType<T>;
}
export function Loadable<T>(loadableProps: LoadableProps<T>) {
return class LoadableComponent extends React.Component<RouteComponentProps<T>, { ResultComponent: React.ComponentType<T> }> {
View mobx-remotedev.d.ts
declare module 'mobx-remotedev' {
/**
* Connect MobX Remote Dev
*
* @param store observable or class to be monitored. In case you want to change its values
* (to time travel or cancel actions), you should export its result as in the example
* above (so we can extend the class).
* @param config Configuration
*
* @return store
@mohsen1
mohsen1 / mobx-router.ts
Created Sep 26, 2016
MobX Router idea
View mobx-router.ts
import {merge} from 'lodash';
import {autorun} from 'mobx';
// TODO: find a good polyfill for this
declare const URLSearchParams;
const routeMatcher = require("route-matcher").routeMatcher;
const createBrowserHistory = require('history/createBrowserHistory').default;
/*
* A store have to implement these two getters to be routable
@mohsen1
mohsen1 / keybindings.json.yaml
Last active Nov 4, 2018
Sublime Text key bindings for Visual Studio Code
View keybindings.json.yaml
[
{
"key": "shift+cmd+d",
"command": "editor.action.copyLinesDownAction"
},
{
"key": "cmd+l",
"command": "expandLineSelection"
},
You can’t perform that action at this time.