Skip to content

Commit

Permalink
config type saga, fix flipper ios
Browse files Browse the repository at this point in the history
  • Loading branch information
ngocle2497 committed May 10, 2021
1 parent e60fc82 commit 391b9cd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rn-boiler-template",
"version": "1.64.10",
"version": "1.64.11",
"description": "Clean and minimalist React Native template for a quick start with TypeScript and components",
"scripts": {
"test": "exit 0"
Expand Down
2 changes: 1 addition & 1 deletion template/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ target 'HelloWorld' do
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable the next line.
use_flipper!()
use_flipper!({ 'Flipper-Folly' => '2.5.3', 'Flipper' => '0.87.0', 'Flipper-RSocket' => '1.3.1' })

post_install do |installer|
react_native_post_install(installer)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {ResponseBase} from '@config/type';
import {ServiceSaga} from '@networking';
import {Action} from 'redux';
import {call, put} from 'redux-saga/effects';
Expand All @@ -9,7 +10,7 @@ export function* onLogin(action: Action) {
if (actions.onLogin.match(action)) {
const {body, onFailure, onSucceeded, url} = action.payload;
yield put(actions.onStart());
const response = yield ServiceSaga.Post(url, body);
const response: ResponseBase<any> = yield ServiceSaga.Post(url, body);
if (response) {
if (response.data) {
if (onCheckType(onSucceeded, 'function')) {
Expand Down
36 changes: 28 additions & 8 deletions template/src/app/library/networking/saga.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {ResponseBase} from '@config/type';
import {StyleSheet} from 'react-native';
import {TIME_OUT, RESULT_CODE_PUSH_OUT} from '@config/api';
import {AppState} from '@app_redux/type';
Expand All @@ -12,7 +13,7 @@ import {ApiConstants} from './api';
import {handleResponseAxios, handleErrorAxios, _onPushLogout} from './helper';

const tokenKeyHeader = 'authorization';
let refreshTokenRequest: Promise<any> | null = null;
let refreshTokenRequest: Promise<string> | null = null;
const AxiosInstance = Axios.create({});

AxiosInstance.interceptors.response.use(
Expand Down Expand Up @@ -50,7 +51,10 @@ async function refreshToken(originalRequest: any) {
}

// base
function* Request(config: AxiosRequestConfig, isCheckOut = true) {
function* Request<T = unknown>(
config: AxiosRequestConfig,
isCheckOut = true,
): Generator<unknown, ResponseBase<T>, any> {
const {token, appUrl}: AppState = yield select((x: any) => x.app);
const defaultConfig: AxiosRequestConfig = {
baseURL: appUrl,
Expand All @@ -63,7 +67,7 @@ function* Request(config: AxiosRequestConfig, isCheckOut = true) {
return yield AxiosInstance.request(
StyleSheet.flatten([defaultConfig, config]),
)
.then((res: any) => {
.then((res: AxiosResponse<T>) => {
const result = handleResponseAxios(res);
return result;
})
Expand All @@ -81,29 +85,45 @@ function* Request(config: AxiosRequestConfig, isCheckOut = true) {
});
}
// get
function* Get(url: string, param?: any) {
function* Get<T>(
url: string,
param?: any,
): Generator<unknown, ResponseBase<T>, any> {
return yield Request({url: url, params: param, method: 'GET'});
}

// post
function* Post(url: string, data: any) {
function* Post<T>(
url: string,
data: any,
): Generator<unknown, ResponseBase<T>, any> {
return yield Request({url: url, data: data, method: 'POST'});
}

// post file
function* PostWithFile(url: string, data: any) {
function* PostWithFile<T>(
url: string,
data: any,
): Generator<unknown, ResponseBase<T>, any> {
const {token}: AppState = yield select((x: RootState) => x.app);
const header: any = {token: token, 'Content-Type': 'multipart/form-data'};
return yield Request({url: url, data: data, method: 'POST', headers: header});
}

// put
function* Put(url: string, data: any, params?: any) {
function* Put<T>(
url: string,
data: any,
params?: any,
): Generator<unknown, ResponseBase<T>, any> {
return yield Request({url: url, data: data, params: params, method: 'PUT'});
}

// delete
function* Delete(url: string, params?: any) {
function* Delete<T>(
url: string,
params?: any,
): Generator<unknown, ResponseBase<T>, any> {
return yield Request({
url: url,
params: params,
Expand Down

0 comments on commit 391b9cd

Please sign in to comment.