Skip to content

Instantly share code, notes, and snippets.

View bardiarastin's full-sized avatar
:octocat:
Living my best life

Bardia Rastin bardiarastin

:octocat:
Living my best life
  • Tehran
View GitHub Profile
import 'package:redux_example/src/redux/posts/posts_actions.dart';
import 'package:redux_example/src/redux/posts/posts_state.dart';
postsReducer(PostsState prevState, SetPostsStateAction action) {
final payload = action.postsState;
return prevState.copyWith(
isError: payload.isError,
isLoading: payload.isLoading,
posts: payload.posts,
);
import 'dart:convert';
import 'package:redux/redux.dart';
import 'package:meta/meta.dart';
import 'package:redux_example/src/models/i_post.dart';
import 'package:redux_example/src/redux/posts/posts_state.dart';
import 'package:redux_example/src/redux/store.dart';
import 'package:http/http.dart' as http;
@immutable
import 'package:meta/meta.dart';
import 'package:redux/redux.dart';
import 'package:redux_example/src/redux/posts/posts_actions.dart';
import 'package:redux_example/src/redux/posts/posts_reducer.dart';
import 'package:redux_example/src/redux/posts/posts_state.dart';
import 'package:redux_thunk/redux_thunk.dart';
AppState appReducer(AppState state, dynamic action) {
if (action is SetPostsStateAction) {
final nextPostsState = postsReducer(state.postsState, action);
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux_example/src/models/i_post.dart';
import 'package:redux_example/src/redux/posts/posts_actions.dart';
import 'package:redux_example/src/redux/store.dart';
void main() async {
await Redux.init();
runApp(MyApp());
class IPost {
int id;
int userId;
String title;
String body;
IPost.fromJson(Map<String, dynamic> json) {
if (json == null) return;
id = json['id'];
userId = json['userId'];
import 'package:meta/meta.dart';
import 'package:redux_example/src/models/i_post.dart';
@immutable
class PostsState {
final bool isError;
final bool isLoading;
final List<IPost> posts;
PostsState({
@bardiarastin
bardiarastin / useApi.ts
Last active September 10, 2020 03:43
simple React custom hook for api access
import { useState, useEffect } from "react";
import { AxiosPromise } from "axios";
interface IState<T = any> {
isLoading: boolean;
isError: boolean;
data: T;
}
const initialState: IState = {
const ProxyChain = require('proxy-chain');
const server = new ProxyChain.Server({
port: 8000,
verbose: false,
prepareRequestFunction: ({ request, username, password, hostname, port, isHttp }) => {
return {
requestAuthentication: username !== 'myusername' || password !== 'mypassword'
};
},
});
@bardiarastin
bardiarastin / cloudSettings
Last active December 17, 2017 09:12
Visual Studio Code Settings Sync Gist
{"lastUpload":"2017-12-17T09:12:16.943Z","extensionVersion":"v2.8.7"}