Apollo With TypeScript
Original
Start with a simple React Component wrapped with the graphql higher order component from React Apollo.
123456789101112131415161718192021222324252627282930313233343536373839404142import React from 'react'import gql from 'graphql-tag'import { graphql } from 'react-apollo'export const HERO_QUERY = gql` query GetCharacter($episode: Episodi!) { hero(episode: $episode) { name id friends { name id ap ...
Source Code of Koa-Static
Source Code12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576'use strict'/** * Module Dependencies */const debug = require('debug')('koa-static')const { resolve } = require('path')const assert = require('assert')const send = require('koa-send')/** * Expose `serve()` */module.exports = serve/** * Serve static files from `root` * * @para ...
React-Hot-Loader in Webpack With Ts-Loader
It’s very easy to integrate react-hot-loader into webpack with ts-loader.
Config the webpackAdd Hot Module Replacement1234567891011121314// webpack.entryapp: [ 'webpack/hot/only-dev-server', 'webpack-dev-server/client?http://localhost:8080', path.resolve(__dirname, './src'),],plugins: [ new webpack.HotModuleReplacementPlugin()],devServer: { hot: true,}
Add React-Hot-Loader into webpack12345678910111213141516171819// add react-hot-loader to entry poin ...
Methods of Observable
OriginalPlayground
ObservableDirect Subclass
ConnectableObservable
GroupedObservable
Subject
Indirect Subclass
AnonymousSubject
AsyncSubject
BehaviorSubject
ReplaySubject
Static Public Methods
bindCallback
public static bindCallback(func: function, selector: function, schedular: Schedular): function(...params: *): Observable
Convert a callback API to a function that returns an Observable
Give it a function f of type f(x, callback) and it will return a function g taht when called as g( ...
HTTP Timings in Node.js
Original
Some Basic Concepts:
IP(Internet Protocol): IP is a network-layer protocol, deals with network addressing and routing. IP is responsible for delivering packets from the source host to the destination host based on the packet headers across one or more IP network. It also defines packet structures that encapsulate the data to be delivered.
DNS(Domain Name Server): DNS is a hierarchical decentralized naming system used to resolve human-readable hostnames into machine-readable IP address. ...
Graphql-Koa-Starter
Init ProjectAdd tsconfig12345678910111213141516171819202122// tsconfig.json{ "files": [ "server.ts" ], "compilerOptions": { "outDir": "./build", "target": "es2015", "module": "commonjs", "moduleResolution": "Node", "sourceMap": true, "pretty": true, "strictNullChecks": true, "lib": [ "esnext" ...
Tag Picture in Html
The picture element is a markup pattern that allows developers to declare multiple sources for an image.
This markup is a container used to specify multiple <source> elements for a specific <img> contained in it.
12345<picture> <source media="(min-width: 40em)" srcset="big.jpg 1x, big-hd.jgp 2x" /> <source srcset="small.jpg 1x, small-hd.jpg 2x" /> <img src="fallback.jpg" /></picture>
Use the media attributeThe ...
Simple Example of DAPP
Use truffle to init ProjectContract of Adoption1234567891011121314151617// contracts/Adoption.solpragma solidity ^0.4.4;constract Adoption { address[16] public adopters; function adopt (uint petId) public returns (uint) { require(petId >= 0 && petId <= 15); adopters[petId] = msg.sender; return petId; } function getAdopters () public returns (addresss[16]) { return adopters; }}
Test123456789101112131415161718192 ...
Options of Webpack Dll Plugin
The DllPlugin and DllReferencePlugin provide means to split bundles in a way that can drastically improve build time performance.
DllPluginThis plugin used in a separate webpack config exclusively to create a dll-only-bundle.
It creates a manifest.json file, which is used by the DllReferencePlugin to map dependencies.
context: (optional), context of requests in the manifest file(default to the webpack context).
name: name of the exposed dll function(TemplatePaths: [hash] & [name])
path: a ...
Optimize Web App
Optimizing All AssetsOne of the most powerful, but under-utilized ways to significantly improve performance starts with understanding hwo the browser analyzes and serves assets. It turns out that browsers are pretty great at discovering resources while parsing and determing their priority of the fly. Here’s where the critical Request comes in:
A request is critical if it contains assets that are necessary to render the content within the users’ viewport.
For most sites, it’d be HTML, necessary ...
Concept on BlockChain
A Blockchain is
A distributed database that is used to maintain a continuously growing list of records, called block.
A Block contains following information:
Index(Block #) - Which block is it? (Genesis block has index 0)
Hash: Is the block valid?
Previous Hash: It the previous block valid?
Timestamp: When was the block added?
Data: What information is stored on the block?
Nonce: How many iterations did we go through before we found a valid block?
Genesis BlockEvery Blockchain will st ...
Build Node CLI
Dependencies
chalk: colorize the output
clear: clears the terminal screen
clui: draws command line tables, gauges and spinners
figlet: creates ASCII art from text
inquirer - create interactive command line user interface
minimist - parses argument options
preferences - manage CLI application encrypted preferences
chalk
chalk.<style>[.<style>...](string, [string...])
chalk.red.bold.underline(‘Hello’, ‘World’)
chalk`string {<style> <style>… string} string`
chal ...
Start Up With Ts, React, Router, Redux, Rxjs
The Repo
Dependencies12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849"devDependencies": { "@types/react": "^16.0.5", "@types/react-dom": "^15.5.4", "@types/react-redux": "^5.0.6", "@types/redux-actions": "^1.2.8", "@types/webpack": "^3.0.10", "@types/webpack-dev-server": "^2.4.1", "autoprefixer": "^7. ...
Notes on TS + React + Redux
Add Explicit Props Interface from StoreWhen I use react-redux, the TS Compiler always throw an error:
1error TS2339: Property '...' does not exist on type 'Readonly<children?: ReactNode; }> & Readonly<{}>'.
That’s because Connect was not supplying an explicit interface to the container component, so it was confused by the prop that it was trying to pass.
So you can add an explicit interface on child component.
12345678interface PropsFromStore e ...
AsyncRoute With React-Router-V4
123456789101112131415161718192021222324252627282930313233343536// AsyncRoute.jsximport React, { Component } from 'react'class Bundle extends Component { constructur() { super() this.state = { mod: null, } } componentWillMount() { this.load(this.props) } componentWillReceiveProps(nextProps) { if (nextProps.load !== this.props.load) { this.load(nextProps) } } load(props) { this.set ...
Note of Sw-Precache
A node module to generate service worker code that will precaches specific resource so they work offline.
Serving your local static resources cache-first means that you can get all the crucial scaffolding for your web app – your app shell – on the screen without having to wait for any network responses.
Installation1yarn add --dev sw-precache
Overview
Make sure your site is served using HTTPS.
incorporate sw-precache into your node-based build script.
Register the service worker JavaScript.
...
Service-Worker With Webpack
1yarn add --dev sw-precache-webpack-plugin
12345678910111213// webpacknew SWPrecachePlugin({ cacheId: 'demo', filename: 'service-worker.js', dontCacheBustUrlsMatching: false, staticFileGlobsIgnorePatterns: [ /index\.html$/, /\.map$/, /\.css$/, /\.svg$/, /\.eot$/, ]})
This will generate service-worker.js in dist.
Add Router1app.use('/service-worker.js', serve('./dist/service-worker.js'))
Note: [name].[ext]?[hash] will not b ...
Snippets of Nginx
nginx.confOne server{} for a site service.
Use location to specify router of requests.
proxy_pass target to delegate inverse .
root dir to specify static files directory.
server_name to set domains whose requests will be handled.
123456789101112// a node server listening to 3000// handle requests from example.comserver { listen: 80; server_name: example.com; location / { index index.html; root: /public/; proxy_pass http://location:3000 }}
Gzi ...
Manipulate Data in D3
Use data imported from a csv file with spaces in the headerWhen importing data from a csv file(dataSpace.csv) that has headers with spaces in the middle of some of the fields there is need to address the data slightly differently in order for it to be used easily in your JavaScript.
12Date Purchased,close1-May-12,58.13
When we go to import the data using the d3.csv function, we need to reference the Data Purchased column in a way that makes allowances for the space. The following piece of scrip ...
Styles in D3
fillThe fill style will fill the element being presented with a specifed color.
By default, most element will be filled with black.
strokeThe stroke style applies a color to lines
opacityThe opacity style has the effect of varying an element’s transparency.
The valid range for opacity is from 0 to 1.
We should make the distinction at this point that opacity affects the entire element, whereas the following fill-opacity and stroke-opacity affect only the fill and stroke respectively.
fill-opacity ...