andywer / andywer/ideabox

Frontend ORM for handling REST resources

未关闭
#2 7 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
没有语言数据
星标
1
派生
1
PR 合并指标
30 天内没有已合并 PR

描述

I think it would be very useful to have something like an ORM for the frontend to fetch and manipulate REST resources. Especially if your backend goes an HATEOASish approach, since you want a tight coupling of resource and href (see https://www.npmjs.com/package/hal). There seems to be no suitable solution out there: https://www.google.de/search?q=redux%20hateoas

Idea:

``` js
////////////////
// Basic usage:

const User = createRestResourceType('user')

const user = await User.fetch('/href/to/user')
const users = await User.fetchAll('/href/to/all/users')

let newUser
// create new empty user instance, do not POST to server yet
newUser = User.new(userData)
// create new user instance, provide data, POST immediately
newUser = await User.create('/href/to/POST/to', userData)

user.update(userData)
user.destroy()

// API should be quite similar to existing JS ORMs like mongoose & sequelize
// Enumerating an instance's properties returns exactly the underlying REST object's properties

///////////////////
// Redux bindings:

bindActionCreators(User)
const reducers = reducersFor(User)

///////////////////////////////
// What the bindActionCreators() does:

User.on('fetchSuccess', (href, data) => (
dispatch({
// could use https://www.npmjs.com/package/action-names
type: actionTypesFor(User).fetchSuccess,
payload: { href, data: User.new(data) }
})
))

// ...
```

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。