andywer / andywer/ideabox

Frontend ORM for handling REST resources

Abierto
#2 7 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Sin datos de lenguaje
Estrellas
1
Forks
1
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

// ...
```

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.