Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danielberndt/mate
work in progress - only for the brave
https://github.com/danielberndt/mate
Last synced: 3 months ago
JSON representation
work in progress - only for the brave
- Host: GitHub
- URL: https://github.com/danielberndt/mate
- Owner: danielberndt
- Created: 2015-06-11T14:28:47.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-06-11T17:37:48.000Z (over 9 years ago)
- Last Synced: 2023-03-24T08:46:12.250Z (almost 2 years ago)
- Language: JavaScript
- Homepage:
- Size: 117 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
_work in progress_
# GOALS:
## Minimal API:
- `defineApi({...})`
- `@load({task: (api, props) => api.getTask(props.taskId)})` possible shortcut: `@load("task")`## Smart field loading:
`this.props.task.title` causes getter to load 'title' attribute from api (returns 'undefined' in the meantime)
## Optimistic Changes:
`api.updateTask(task, {attr})` will push **attr** to the `pending change queue`
## Todos
- [x] api-description-normaliser
- [x] tests
- [ ] models
- [ ] research properties
- [ ] register calls
- [ ] model updated data / update dependencies
- [ ] collections
- [ ] sketch out (mockable) api-http-layer interface
- [ ] optimisic changes queue (associated with request)
- [ ] ... and much morekinds of data:
- collection: `/tasks?title=hi` (contains ref to models)
- singleton-ref: `/logged-in-user` (contains ref to user) ... model needs to update once underlying user changes
- singleton: `/settings`
- model: `/task/23````
apiDescription = {
task: {
singleton: true,
fields: ["id,name", {commentCount: {deps: ["comment.taskId"]}}, {deckId: {default: []}}]
},
tasks: { // used for creation, deletion
copyFieldsFrom: "task"
},
tasksViaTitle: {
// DON'T define it here!
// we need a different layer for this (models,ids,fields) => api-call
endpoint: (data) => `/tasks?title=${data}` // default is /{model-name}/{data},
deps: ['task.title']
},
commentsViaTask: {
modelName: "comment",
endpoint: (data) => `/comments?taskId=${data}`
},
deck: {
singleton: true,
deps: {
taskCount: ['task.deckId'],
effortCount: ['task.deckId', 'task.effort']
blockedTasks: ['task.deckId', 'task.status']
}
},
loggedInUser: {
singleton: true,
}
}api.createTask(task) =>
send Data
-> once arrived update all deps with 'task.*'api.createCommentsViaTask({data}) =>
send Data
-> once arrived update all deps with '${modelName}.*'
add (optimistic) comment to queueapi.deleteTask(taskId) => update all deps with 'task.*'
api.updateTask(oldTask,{prop1, prop2}) :
- sendData
- add {Task: {id, prop1, prop2}, fetchTask} to processing queue
- check if prop1, prop2 differ from oldTask. if so update deps with 'modelName.prop1,prop2'whenever fetching data:
if prev data changed: update deps with 'modelName.propChange'api.getTask(id) =>
returns empty Object immediately, set up with es5 properties@load({
task: (api, props) => api.getTask(props.taskId),
})
class myComp {handleSubmit({data}) {
return api.createTask({data});
},render() {
return{this.task.title}
}}
// possibly:
@load({
task: (api, props) => api.getTask(props.taskId),
attachment: ["task.attachmentId", (api, props, {task}) => api.getAttachment(task.attachmentId)]
})api.getTask(props.taskId) -> {
data,
listeners,
isLoading,
error,
name
}
```