kuu-tools
v0.3.2
Published
Kuu front-end tools
Downloads
20
Readme
kuu-tools
Kuu front-end tools
Install
npm i kuu-tools
Request utils
GET
import { get } from 'kuu-tools'
const data = await get('/member/get?foo=1&bar=2')
POST
import { post } from 'kuu-tools'
const data = await post('/member/signup', { user: 'foo', name: 'bar' })
PUT
import { put } from 'kuu-tools'
const data = await put('/member/signup?foo=1&bar=2', { user: 'foo', name: 'bar' })
DELETE
import { del } from 'kuu-tools'
const data = await del('/member/signup?foo=1&bar=2', { user: 'foo', name: 'bar' })
Model SDK
Create
https://github.com/kuuland/kuu#create-record
import { create } from 'kuu-tools'
// create a role
const data = await create('Role', { Code: 'foo', Name: 'bar' })
// batch create roles
const data = await create('Role', [{ Code: 'foo1', Name: 'bar1' }, { Code: 'foo2', Name: 'bar2' }])
Update
https://github.com/kuuland/kuu#update-fields
import { update } from 'kuu-tools'
// update a param
const data = await update('param', { ID: 5 }, { Value: 'new value', Name: 'foobar' })
// batch updates
const data = await update('param', { ID: { $in: [5, 10, 11] } }, { Value: 'new value' }, true)
Delete
https://github.com/kuuland/kuu#delete-record
import { remove } from 'kuu-tools'
// delete a param
const data = await remove('param', { ID: 5 })
// batch delete
const data = await remove('param', { ID: { $in: [5, 10, 11] } }, true)
// batch and unsoft delete
const data = await remove('param', { ID: { $in: [5, 10, 11] } }, true, true)
Query
https://github.com/kuuland/kuu#query
import { list, one, id } from 'kuu-tools'
// list query
const data = await list('param', { cond: { ID: { $in: [5, 10, 11] } }, page: 3, sort: '-CreatedAt' })
// query only one record
const data = await one('param', { cond: { Name: 'foo' } })
// query by id
const data = await id('param', 11)
i18n
{
"hello": "你好",
"welcome": "欢迎 {{name}}"
}
import { withLocale } from 'kuu-tools'
class Param extends React.Component {
render () {
return (
<div>
<div>{this.props.L('hello', 'Hello')}</div> /* => 你好 */
<div>{this.props.L('not_found', 'Not found')}</div> /* => Not found */
<div>{this.props.L('welcome', 'Welcome Kuu', { name: 'Kuu' }}</div> /* => 欢迎 Kuu */
</div>
)
}
}
export default withLocale(Param)
Notes:
this.props.L
can only be used inrender
, otherwise it will not respond to language updates in real time.withLocale(Param)
withLocale(withRouter(Param))
withLocale(connect(mapStateToProps)(withRouter(Param)))
Message supports the mustache syntax.