https://github.com/dev360/domain-model
Django-style Domain Models for your Javascript
https://github.com/dev360/domain-model
Last synced: 10 months ago
JSON representation
Django-style Domain Models for your Javascript
- Host: GitHub
- URL: https://github.com/dev360/domain-model
- Owner: dev360
- License: mit
- Created: 2016-06-30T22:51:29.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-08-09T00:32:41.000Z (almost 10 years ago)
- Last Synced: 2025-08-09T04:48:28.143Z (11 months ago)
- Language: JavaScript
- Homepage:
- Size: 38.1 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# domain-model
Allows you to define django-style [domain driven models](http://martinfowler.com/eaaCatalog/domainModel.html) for your REST endpoints in javascript. See [wiki](https://github.com/dev360/domain-model/wiki) for more information about the API.
Built on top of `isomorphic-fetch`, and returns ES6 promises. Originally intended to be used with react/redux.
## To install
```npm install domain-model```
## Example
```js
import { Model, fields } from 'domain-model'
class Company extends Model {}
Company.register()
class Address extends Model {}
Address.register()
export class User extends Model {
get displayName() {
return `${this.name} [${this.email}]`
}
static get address() {
return new fields.ForeignKey({ model: 'Address' })
}
static get company() {
return new fields.ForeignKey({ model: 'Company' })
}
static get Meta() {
return {
detail_url: 'https://jsonplaceholder.typicode.com/users/{id}/',
list_url: 'https://jsonplaceholder.typicode.com/users/',
}
}
}
User.register()
...
// To use:
User.objects.get({ id: 1 }).then((user) => {
console.dir(user)
})
User.objects.all().then((users) => {
console.dir(users)
})
```