Skip to content

Instantly share code, notes, and snippets.

View Quramy's full-sized avatar
👾

Yosuke Kurami Quramy

👾
View GitHub Profile
@Quramy
Quramy / how-to-fix.js
Last active January 15, 2019 05:36
minimal reproducer for nested dispatching error with spork / thunk
require('babel-polyfill');
const { createStore, applyMiddleware, bindActionCreators, compose } = require('redux');
const { enableBatching, batchActions, batchDispatchMiddleware, BATCH } = require('redux-batched-actions');
const thunk = require('redux-thunk').default;
const { fork, createMiddleware } = require('redux-spork');
function main() {
// reducer
const count = (prev = 0, action) => {
@Quramy
Quramy / _readme.md
Created November 14, 2018 01:56
extract identifiers and split files

I want a tsssercmd to extract a selected identifier (function, const, class, type, etc...) to other new file.

{
  command: "extractAndCreateFile",
  file: "./main.js",
  location: {
    line: 2, col: 10
  },
 toFile: "./sum.js"
@Quramy
Quramy / combineLatest.ts
Created September 21, 2018 16:17
Example of TS 3.1 Mapped Tuple Type
interface Observable<T> {
subscribe(cb: (v: T) => void): void;
}
type StreamValue<S> = S extends Observable<infer T> ? T : never;
type Unwrap<S> = { [P in keyof S]: StreamValue<S[P]> };
declare function combineLatest<U extends Observable<any>[]>(...streams: U): Observable<Unwrap<U>>;
@Quramy
Quramy / main.ts
Created February 5, 2018 07:10
Value mocking example using type inference in conditional types
type RT<F> = F extends (...args: any[]) => infer R ? R : never;
interface Proxy<T, K extends keyof T> {
returnValue(value: RT<T[K]>): this;
}
declare function spyOn<T, K extends keyof T>(obj: T, methodName: K): {
and: Proxy<T, K>;
};
const serviceToTest = {
@Quramy
Quramy / schema_gen.ts
Created January 4, 2018 09:42
Generate .d.ts from JSON schema using @ngtools/json-schema
import { SchemaClassFactory } from '@ngtools/json-schema';
// Input JSON schema json file
const factory = SchemaClassFactory<any>(require('@angular/cli/lib/config/schema.json'));
const schemaClass = new factory(null);
// Output .d.ts
console.log(schemaClass.$$serialize('text/x.dts'));
@Quramy
Quramy / params.json
Created September 22, 2017 02:38
get commit id from tagname
{
"owner": "Quramy",
"repository": "tsuquyomi",
"tag": "v0.8.0"
}
@Quramy
Quramy / README.md
Last active September 4, 2020 17:24
Performance Angular unit testing

Performance of unit testing Angular app

I'm loving Angular, but running unit tests on Karma gets my nerves. It's too slow for me.

In this post, I explain mechanics under Angular's testing module and how to improve the performance.

What makes my tests slow?

To evaluate Angular unit testing performance I captured the CPU profiling with running Karma.

@Quramy
Quramy / pluginModuleFactory.ts
Created March 21, 2017 20:50
TS 2.3 Language Service Plugin for completion GraphQL Query
import * as ts from 'typescript/lib/tsserverlibrary';
const { buildClientSchema } = require('graphql');
const { getAutocompleteSuggestions } = require('graphql-language-service-interface');
// TODO replace the result by introspection query
const introspectionJson = require('../schema.json');
const schema = buildClientSchema(introspectionJson.data);
function findNode(sourceFile: ts.SourceFile, position: number): ts.Node | undefined {
@Quramy
Quramy / ng2-load-children-loader.js
Last active September 1, 2016 15:40
A webpack loader for Angular2 Lazy Module Loading
var path = require("path");
var loadChildrenRegex = /loadChildren\s*:(.*)$/gm;
var ngfactoryRegex = /\.ngfactory(\.|$)/;
var stringRegex = /(['"])((?:[^\\]\\\1|.)*?)\1/g;
function replacePath(str, addSuffix) {
return str.replace(stringRegex, function(match, quote, pathAndFragment) {
var tmp = pathAndFragment.split("#");
var fpath = addSuffix ? tmp[0] + ".ngfactory" : tmp[0];
var moduleName;
@Quramy
Quramy / app.module.ts
Last active August 18, 2016 08:04
ng2 lazy load routing
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { MyApp } from './my-app.component';
import { routing , appRoutingProviders } from "./app.routing";
import { TopComponent } from "./top.component";
import { AboutComponent } from "./about.component";
//import { SubModule } from "./sub/sub.module";