andywer / andywer/ideabox

Frontend ORM for handling REST resources

Đang mở
#2 7 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Không có dữ liệu ngôn ngữ
Star
1
Fork
1
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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) }
})
))

// ...
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.