Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bagaar/ember-data-extensions
Ember Data extensions to communicate with the Bagaaravel JSON API implementation.
https://github.com/bagaar/ember-data-extensions
bagaar bagaaravel ember ember-addon ember-data
Last synced: about 1 month ago
JSON representation
Ember Data extensions to communicate with the Bagaaravel JSON API implementation.
- Host: GitHub
- URL: https://github.com/bagaar/ember-data-extensions
- Owner: Bagaar
- License: mit
- Created: 2019-02-08T13:36:38.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-02-11T18:45:49.000Z (11 months ago)
- Last Synced: 2024-05-21T18:06:30.830Z (7 months ago)
- Topics: bagaar, bagaaravel, ember, ember-addon, ember-data
- Language: JavaScript
- Homepage:
- Size: 3.96 MB
- Stars: 1
- Watchers: 6
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Bagaaravel Ember Data Extensions
[![CI](https://github.com/Bagaar/ember-data-extensions/workflows/CI/badge.svg)](https://github.com/Bagaar/ember-data-extensions/actions?query=workflow%3ACI)
[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)Ember Data extensions to communicate with the Bagaaravel JSON API implementation.
## Table of Contents
- [Introduction](#introduction)
- [Support](#support)
- [Installation](#installation)
- [Usage](#usage)
- [Contributing](#contributing)
- [License](#license)
- [Maintenance](#maintenance)## Introduction
`@bagaaravel/ember-data-extensions` is an addon that allows you to easily communicate with the Bagaaravel JSON API implementation.
## Support
`@bagaaravel/ember-data-extensions` supports **Ember v4.0 and up**.
## Installation
```shell
ember install @bagaaravel/ember-data-extensions
```## Usage
### 1\. Extend the Application Serializer
```javascript
// app/serializers/application.jsimport {
keyForAttribute,
keyForRelationship,
payloadKeyFromModelName,
serialize,
shouldSerializeHasMany
} from '@bagaaravel/ember-data-extensions/serializer'
import JSONAPISerializer from '@ember-data/serializer/json-api'export default class ApplicationSerializer extends JSONAPISerializer {
// Make sure attribute keys have the correct casing:
keyForAttribute () {
return keyForAttribute(...arguments)
}// Make sure relationship keys have the correct casing:
keyForRelationship () {
return keyForRelationship(...arguments)
}// Make sure model types have the correct casing:
payloadKeyFromModelName () {
return payloadKeyFromModelName(...arguments)
}// Make sure relationships are correctly serialized:
serialize () {
const serialized = super.serialize(...arguments)return serialize(serialized, ...arguments)
}// Check when 'hasMany' relationships should be serialized:
shouldSerializeHasMany () {
const superCheck = super.shouldSerializeHasMany(...arguments)return shouldSerializeHasMany(superCheck, ...arguments)
}
}
```### 2\. Extend the Application Adapter
```javascript
// app/adapters/application.jsimport { urlForUpdateRecord } from '@bagaaravel/ember-data-extensions/adapter'
import JSONAPIAdapter from '@ember-data/adapter/json-api'export default class ApplicationAdapter extends JSONAPIAdapter {
// Make sure the correct URL is used when only saving a relationship:
urlForUpdateRecord () {
const baseUrl = super.urlForUpdateRecord(...arguments)return urlForUpdateRecord(baseUrl, ...arguments)
}
}
```### 3\. Updating Relationships
```javascript
import {
saveRelationship,
saveRelationships
} from '@bagaaravel/ember-data-extensions/model'const user = await this.store.findRecord('user', '1')
// Update the user's projects:
saveRelationship(user, 'projects')// Update the user's company:
saveRelationship(user, 'company')// Update the user's projects and company:
saveRelationships(user, ['projects', 'company'])
```## Contributing
See the [Contributing](CONTRIBUTING.md) guide for details.
## License
This project is licensed under the [MIT License](./LICENSE.md).
## Maintenance
`@bagaaravel/ember-data-extensions` is built and maintained by [Bagaar](https://bagaar.be).