UNPKG

9.6 kBMarkdownView Raw
1<p align="center">
2 <img
3 class="project-logo"
4 src="./ember-data-logo-light.svg#gh-light-mode-only"
5 alt="EmberData"
6 width="240px"
7 title="EmberData"
8 />
9 <img
10 class="project-logo"
11 src="./ember-data-logo-dark.svg#gh-dark-mode-only"
12 alt="EmberData"
13 width="240px"
14 title="EmberData"
15 />
16</p>
17
18<p align="center">The lightweight reactive data library for JavaScript applications</p>
19
20[![Build Status](https://github.com/emberjs/data/workflows/CI/badge.svg)](https://github.com/emberjs/data/actions?workflow=CI)
21[![Discord Community Server](https://img.shields.io/discord/480462759797063690.svg?logo=discord)](https://discord.gg/zT3asNS)
22
23---
24
25Wrangle your application's data management with scalable patterns for developer productivity.
26
27- ⚡️ Committed to Best-In-Class Performance
28- 🌲 Focused on being as svelte as possible
29- 🚀 SSR Ready
30- 🔜 Typescript Support
31- 🐹 Built with ♥️ by [Ember](https://emberjs.com)
32- ⚛️ Supports any API: `GraphQL` `JSON:API` `REST` `tRPC` ...bespoke or a mix
33
34**Tagged Releases**
35
36- ![NPM Canary Version](https://img.shields.io/npm/v/ember-data/canary?label=%40canary&color=FFBF00)
37- ![NPM Beta Version](https://img.shields.io/npm/v/ember-data/beta?label=%40beta&color=ff00ff)
38- ![NPM Stable Version](https://img.shields.io/npm/v/ember-data/latest?label=%40latest&color=90EE90)
39- ![NPM LTS Version](https://img.shields.io/npm/v/ember-data/lts?label=%40lts&color=0096FF)
40- ![NPM LTS 4.12 Version](https://img.shields.io/npm/v/ember-data/lts-4-12?label=%40lts-4-12&color=bbbbbb)
41
42### 📖 On This Page
43
44- [Overview](#overview)
45 - [Architecture](#-architecture)
46 - [Basic Installation](#basic-installation)
47 - [Advanced Installation](#advanced-installation)
48- [Configuration](#configuration)
49 - [Deprecation Stripping](#deprecation-stripping)
50 - [randomUUID polyfill](#randomuuid-polyfill)
51 - [Removing inspector support in production](#removing-inspector-support-in-production)
52 - [Debugging](#debugging)
53- [Contributing](#contributing)
54
55# Overview
56
57*Ember***Data** is a lightweight reactive data library for JavaScript applications that provides composable primitives for ordering query/mutation/peek flows, managing network and cache, and reducing data for presentation.
58
59- [API Documentation](https://api.emberjs.com/ember-data/release)
60- [Community & Help](https://emberjs.com/community)
61- [Contributing Guide](./CONTRIBUTING.md)
62- [Usage Guide](https://guides.emberjs.com/release/models/)
63- [RFCs](https://github.com/emberjs/rfcs/labels/T-ember-data)
64- [Team](https://emberjs.com/team)
65- [Blog](https://emberjs.com/blog)
66
67## 🪜 Architecture
68
69*Ember***Data** is both _resource_ centric and _document_ centric in it's approach to caching, requesting and presenting data. Your application's configuration and usage drives which is important and when.
70
71The `Store` is a **coordinator**. When using a `Store` you configure what cache to use, how cache data should be presented to the UI, and where it should look for requested data when it is not available in the cache.
72
73This coordination is handled opaquely to the nature of the requests issued and the format of the data being handled. This approach gives applications broad flexibility to configure *Ember***Data** to best suite their needs. This makes *Ember***Data** a powerful solution for applications regardless of their size and complexity.
74
75*Ember***Data** is designed to scale, with a religious focus on performance and asset-size to keep its footprint small but speedy while still being able to handle large complex APIs in huge data-driven applications with no additional code and no added application complexity. It's goal is to prevent applications from writing code to manage data that is difficult to maintain or reason about.
76
77*Ember***Data**'s power comes not from specific features, data formats, or adherence to specific API specs such as `JSON:API` `trpc` or `GraphQL`, but from solid conventions around requesting and mutating data developed over decades of experience scaling developer productivity.
78
79## Basic Installation
80
81Install using your javascript package manager of choice. For instance with [pnpm](https://pnpm.io/)
82
83```no-highlight
84pnpm add ember-data
85```
86
87`ember-data` is installed by default for new applications generated with `ember-cli`. You can check what version is installed by looking in the `devDependencies` hash of your project's [package.json](https://docs.npmjs.com/cli/v8/configuring-npm/package-json) file.
88
89If you have generated a new `Ember` application using `ember-cli` but do
90not wish to use `ember-data`, remove `ember-data` from your project's `package.json` file and run your package manager's install command to update your lockfile.
91
92## Advanced Installation
93
94*Ember***Data** is organized into primitives that compose together via public APIs.
95
96- [@ember-data/request](./packages/request) provides managed `fetch` via its RequestManager and can be used without any other parts of EmberData.
97- [@ember-data/store](./packages/store) is the "core" of EmberData and handles coordination between the RequestManager, the Cache, and Presentation Concerns.
98- [@ember-data/tracking](./packages/tracking) is currently required when using the core and provides tracking primitives for change notification of Tracked properties.
99- [@ember-data/json-api](./packages/json-api) is a resource cache for JSON:API structured data. It integrates with the store via the hook `createCache`
100- [@ember-data/model](./packages/model) is a presentation layer, it integrates with the store via the hooks `instantiateRecord` and `teardownRecord`.
101- [@ember-data/debug](./packages/debug) provides (optional) debugging support for the `ember-inspector`.
102
103
104Some EmberData APIs are older than others, and these still interop via well-defined public API boundaries but are
105no longer the ideal approach.
106
107- [@ember-data/legacy-compat](./packages/legacy-compat) provides support for older paradigms that are being phased out
108- [@ember-data/adapter](./packages/adapter) provides various network API integrations for APIS built over specific REST or JSON:API conventions. It integrates with the Store via `store.adapterFor`, and with the request pipeline via the `LegacyNetworkHandler` available via `@ember-data/legacy-compat` which utilizes the Minimum Adapter Interface.
109- [@ember-data/serializer](./packages/serializer) pairs with `@ember-data/adapter` and the `LegacyNetworkHandler` to normalize and serialize data to and from an API format into the `JSON:API` format understood by `@ember-data/json-api`.
110
111And finally:
112
113- [ember-data](./packages/-ember-data) is a "meta" package which bundles all of these together for convenience
114
115The packages interop with each other through well defined public API boundaries. The core
116of the library is the store provided by `@ember-data/store`, while each of the other libraries plugs into the store when installed. Because these packages interop via fully
117public APIs, other libraries or applications may provide their own implementations. For instance, [ember-m3](https://github.com/hjdivad/ember-m3) is a commonly used presentation and cache implementation suitable for complex resource objects and graphs.
118
119## Configuration
120
121### Deprecation Stripping
122
123*Ember***Data** allows users to opt-in and remove code that exists to support deprecated behaviors.
124
125If your app has resolved all deprecations present in a given version, you may specify that version as your "compatibility" version to remove the code that supported the deprecated behavior from your app.
126
127```ts
128let app = new EmberApp(defaults, {
129 emberData: {
130 compatWith: '4.8',
131 },
132});
133```
134
135- [Full Documentation](https://api.emberjs.com/ember-data/release/modules/@ember-data%2Fdeprecations)
136
137### randomUUID polyfill
138
139*Ember***Data** uses `UUID V4` by default to generate identifiers for new data created on the client. Identifier generation is configurable, but we also for convenience will polyfill
140the necessary feature if your browser support or deployment environment demands it. To
141activate this polyfill:
142
143```ts
144let app = new EmberApp(defaults, {
145 '@embroider/macros': {
146 setConfig: {
147 '@ember-data/store': {
148 polyfillUUID: true,
149 },
150 },
151 },
152});
153```
154
155### removing inspector support in production
156
157If you do not want to ship inspector support in your production application, you can specify
158that all support for it should be stripped from the build.
159
160```ts
161let app = new EmberApp(defaults, {
162 emberData: {
163 includeDataAdapterInProduction: false,
164 },
165});
166```
167
168- [Full Documentation](https://api.emberjs.com/ember-data/release/modules/@ember-data%2Fdebug)
169
170### Debugging
171
172Many portions of the internals are helpfully instrumented with logging that can be activated
173at build time. This instrumentation is always removed from production builds or any builds
174that has not explicitly activated it. To activate it set the appropriate flag to `true`.
175
176```ts
177let app = new EmberApp(defaults, {
178 emberData: {
179 debug: {
180 LOG_PAYLOADS: false, // data store received to update cache with
181 LOG_OPERATIONS: false, // updates to cache remote state
182 LOG_MUTATIONS: false, // updates to cache local state
183 LOG_NOTIFICATIONS: false,
184 LOG_REQUESTS: false, // log Requests issued via the request manager
185 LOG_REQUEST_STATUS: false,
186 LOG_IDENTIFIERS: false,
187 LOG_GRAPH: false, // relationship storage
188 LOG_INSTANCE_CACHE: false, // instance creation/deletion
189 },
190 },
191});
192```
193
194### License
195
196This project is licensed under the [MIT License](LICENSE.md).