Skip to content

Instantly share code, notes, and snippets.

View alvinsj's full-sized avatar

Alvin alvinsj

  • Singapore
View GitHub Profile
@alvinsj
alvinsj / advanced-react-free.md
Last active December 4, 2017 09:25
Review of the videos from Advanced React (Free version)

https://courses.reacttraining.com/courses/advanced-react-free

  1. Imperative vs. Declarative, "extending" React
    Making use of react lifecycle to make declarative API (from imperative lib). non-dom, nothing-to-render component. e.g. <Sound />, <Tone />, <D3 />

    • nice: declarative > imperative.
    • maybe? component tree with non-DOM component. e.g. sound(LifeCycleComponent, {isPlaying, pitch, frequency})
  2. Implicit State with Compound Components and cloneElement
    Making use of React.Children.map to inject props to children,

import React from 'react';
import FormWithLayout from 'react-form-with-layout';
import {formInputsSerialize} from 'form-input-serialize';
const Form = (props) => {
const layout = (builder) => {
const {layout, section} = builder;
const col = (type, ...children) => builder.col(`col-${type}`, ...children);
return layout(

Keybase proof

I hereby claim:

  • I am alvinsj on github.
  • I am alvinsj (https://keybase.io/alvinsj) on keybase.
  • I have a public key whose fingerprint is B995 753B 6198 B0ED 48B6 B762 E0B0 9456 C027 0707

To claim this, I am signing this object:

var p1, p2, tp1;
// p1 is original promise
p1 = new Promise(function(resolve, reject){
setTimeout(function(){
console.log('+ resolve to hello');
resolve("hello");
}, 1000)
});
public class Product implements Cachable{
public Product(String type, String key){
mType = type;
mKey = key;
}
public String cacheId() {
return mKey;
}
// Initialization
cacheStore = new CacheStore(getContext()) {
@Override
public String storeName() {
return "ProductsStore";
}
};
// store value
cacheStore.put(TYPE, KEY, VALUE);
new APIRequest( new APIClient(HomeActivity.this), APP_SERVER+"/download_pdf", APIRequest.GET)
.withDefaultParams(defaultParamsHashMap())
.addParam("format", "json")
.addParam("id", pdfId)
.addHeaderParam("Referer", APP_REFERER);
.startDownload(CACHE_ID, DOWNLOAD_FOLDER, new APIDataRequestHandler(){
@Override
public void before(){
showProgressBar();
new APIRequest( new APIClient(HomeActivity.this), APP_SERVER+"/latest_news", APIRequest.GET)
.withDefaultParams(defaultParamsHashMap())
.addParam("format", "json")
.addParam("limit", 10)
.addHeaderParam("Referer", APP_REFERER);
.startWithCache(CacheStategy.RESPONSE_VERSION, CACHE_GROUP_KEY, CACHE_KEY,new JSONRequestHandler(){
@Override
public String getVersion(HttpEntity response){
return versionFromResponse(response);
}
new APIRequest( new APIClient(HomeActivity.this), APP_SERVER+"/search", APIRequest.GET)
.withDefaultParams(defaultParamsHashMap())
.addParam("format", "json")
.addParam("q", searchTerm)
.addHeaderParam("Referer", APP_REFERER);
.start(new JSONRequestHandler(){
@Override
public void before(){
showProgressBar();
class CreateTableS3Uploads < ActiveRecord::Migration
def up
create_table :s3_uploads do |t|
t. :url
t.timestamps
end
end
def down
drop_table :s3_uploads
end