Skip to content

Instantly share code, notes, and snippets.

View adnaan's full-sized avatar
🎯
Focusing

Adnaan Badr adnaan

🎯
Focusing
View GitHub Profile
reducers: {
query(state) {
return { ...state, loading: true, };
},
querySuccess(state, { payload }) {
return { ...state, loading: false, list: payload };
},
vote(state) {
return { ...state, loading: true };
},
effects: { * query(_, { call, put }: { call: Function, put: Function }) {
const { success, data } = yield call(getProducts);
if (success) {
yield put({
type: 'querySuccess',
products: data,
});
}
},
* vote({ id }: { id: number }, { call, put }: { call: Function, put: Function }) {
@adnaan
adnaan / services.js
Last active November 2, 2016 04:58
src/services.js
/*@flow*/
export async function getProducts() {
return fetch(`/api/products`).then(res => res.json())
}
export async function updateVote(id: { id: number }) {
return fetch('/api/products/vote/' + String(id)).then(res => res.json())
}
@adnaan
adnaan / model.js
Last active November 6, 2016 10:04
src/model.js
import { getProducts, updateVote } from './services';
export default {
namespace: 'products',
state: {
list: [],
loading: false,
},
subscriptions: {
init({ dispatch }: { dispatch: Function }) {
@adnaan
adnaan / index.js
Created November 2, 2016 05:00
src/index.js
/*@flow*/
import React from 'react';
import { Router, Route } from 'dva/router';
import dva from 'dva';
import App from './App';
import model from './model';
import './index.css';
const app = dva();
app.model(model);
@adnaan
adnaan / Product.js
Last active November 6, 2016 09:46
/*@flow*/
import React from 'react';
import FaCaretUp from 'react-icons/lib/fa/caret-up';
function Product(props: { id: number, title: string, vote: number, dispatch: Function }) {
const { id, title, vote } = props;
function handleVote() {
props.dispatch({
type: 'products/vote',
/*@flow*/
import React from 'react';
import Product from './Product';
function ProductList(props: { data: Array < { ID: number, title: string, vote: number } > , dispatch: Function }) {
return (
<div >
{
props.data.map(product => <Product
key={product.ID}
/*@flow*/
import React from 'react';
import ProductList from './components/ProductList'
import { connect } from 'react-redux';
const App = connect(({ products }) => ({
products
}))(function(props) {
return (
<div >
@adnaan
adnaan / dep.go
Created July 7, 2017 03:42
Global Dependency
package main
// Using a global dependency
var userService user.Service
func Init() {
userService = user.NewService()
}
func GetComments() []Comment {
var comments []Comment

Keybase proof

I hereby claim:

  • I am adnaan on github.
  • I am adnaan (https://keybase.io/adnaan) on keybase.
  • I have a public key ASAgzL2uEUiEMnnqLkRbqECnLs5vet2p2FQF23eFrf45HAo

To claim this, I am signing this object: