-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from lsky-walt/dev
Dev
- Loading branch information
Showing
10 changed files
with
212 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@lsky/http-react", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main": "./lib/index.js", | ||
"repository": "https://github.com/lsky-walt/http-react.git", | ||
"author": "lsky_walt <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* eslint-disable no-plusplus */ | ||
/* eslint-disable react/button-has-type */ | ||
import React from 'react' | ||
// eslint-disable-next-line import/no-named-as-default | ||
import HttpReact, { Post, Get } from '../../src' | ||
|
||
import { http, post, get } from '../config' | ||
|
||
interface SiteState { | ||
count: number | ||
} | ||
|
||
class Index extends React.Component<{}, SiteState> { | ||
constructor() { | ||
// @ts-ignore | ||
super() | ||
this.state = { | ||
count: 0, | ||
} | ||
} | ||
|
||
render() { | ||
const { count } = this.state | ||
return ( | ||
<div> | ||
<button onClick={() => { | ||
this.setState({ | ||
count: count + 1, | ||
}) | ||
}} | ||
> | ||
count++ | ||
</button> | ||
<HttpReact | ||
url={http.url} | ||
data={{ ...http.data, count }} | ||
method="post" | ||
onResponse={(response) => { console.log('response: ', response) }} | ||
onError={(error) => console.log('error: ', error)} | ||
onLoading={(loading) => console.log('isLoading: ', loading)} | ||
> | ||
<div> | ||
http react | ||
{' '} | ||
{count} | ||
</div> | ||
</HttpReact> | ||
<Post | ||
url={post.url} | ||
data={post.data} | ||
onResponse={(response) => { console.log('post: ', response) }} | ||
> | ||
post http react | ||
</Post> | ||
<Get url={get.url} onResponse={(response) => { console.log('get: ', response) }} loading={<div>loading...</div>} /> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default Index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* eslint-disable no-plusplus */ | ||
/* eslint-disable react/button-has-type */ | ||
import React from 'react' | ||
// eslint-disable-next-line import/no-named-as-default | ||
import HttpReact, { Post, Get } from '../../src' | ||
|
||
import { http, post, get } from '../config' | ||
|
||
interface SiteState { | ||
count: number, | ||
first: boolean, | ||
second: boolean, | ||
third: boolean, | ||
} | ||
|
||
class Index extends React.Component<{}, SiteState> { | ||
first: (flag: any) => void | ||
|
||
third: (flag: any) => void | ||
|
||
second: (flag: any) => void | ||
|
||
constructor() { | ||
// @ts-ignore | ||
super() | ||
this.state = { | ||
count: 0, | ||
first: true, | ||
second: true, | ||
third: true, | ||
} | ||
|
||
this.first = this.update.bind(this, 'first') | ||
this.second = this.update.bind(this, 'second') | ||
this.third = this.update.bind(this, 'third') | ||
} | ||
|
||
update(key: 'first' | 'second' | 'third', flag: boolean) { | ||
// @ts-ignore | ||
this.setState({ | ||
[key]: flag, | ||
}) | ||
} | ||
|
||
render() { | ||
const { | ||
count, first, second, third, | ||
} = this.state | ||
return ( | ||
<div> | ||
<button onClick={() => { | ||
this.setState({ | ||
count: count + 1, | ||
}) | ||
}} | ||
> | ||
count++ | ||
</button> | ||
<HttpReact | ||
url={http.url} | ||
data={{ ...http.data, count }} | ||
method="post" | ||
onResponse={(response) => { console.log('response: ', response) }} | ||
onError={(error) => console.log('error: ', error)} | ||
onLoading={this.first} | ||
> | ||
{ | ||
!first ? ( | ||
<Post | ||
url={post.url} | ||
data={post.data} | ||
onResponse={(response) => { console.log('post: ', response) }} | ||
onLoading={this.second} | ||
> | ||
{ | ||
!second ? ( | ||
<Get | ||
url={get.url} | ||
onResponse={(response) => { console.log('get: ', response) }} | ||
loading={<div>loading...</div>} | ||
onLoading={this.third} | ||
> | ||
{ | ||
!third ? `nested state count: ${count}` : undefined | ||
} | ||
</Get> | ||
) : undefined | ||
} | ||
</Post> | ||
) : undefined | ||
} | ||
</HttpReact> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default Index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.