ember-data

A lightweight reactive data library for javascript applications. Designed o...

README

  <img
    class="project-logo"
    src="./ember-data-logo-light.svg#gh-light-mode-only"
    alt="EmberData"
    width="240px"
    title="EmberData"
    />
  <img
    class="project-logo"
    src="./ember-data-logo-dark.svg#gh-dark-mode-only"
    alt="EmberData"
    width="240px"
    title="EmberData"
    />

The lightweight reactive data library for JavaScript applications

Build Status Code Climate Discord Community Server


Wrangle your application's data management with scalable patterns for developer productivity.

- ⚡️  Committed to Best-In-Class Performance
- 🌲 Focused on being as svelte as possible
- 🚀 SSR Ready
- 🔜 Typescript Support
- 🐹 Built with ♥️ by Ember
- ⚛️ Supports any API: GraphQL JSON:API REST tRPC ...bespoke or a mix

📖 On This Page


  - Debugging

Overview


EmberData 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.




🪜 Architecture


EmberData 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.

The 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.

This 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 EmberData to best suite their needs. This makes EmberData a powerful solution for applications regardless of their size and complexity.

EmberData 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.

EmberData'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.



Basic Installation


Install using your javascript package manager of choice. For instance with pnpm

  1. ```no-highlight
  2. pnpm add ember-data
  3. ```

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 file.

If you have generated a new Ember application using ember-cli but do
not 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.

Advanced Installation


EmberData is organized into primitives that compose together via public APIs.

- @ember-data/store is the core and handles coordination
- @ember-data/tracking is required when using the core and provides tracking primitives for change notification of Tracked properties
- @ember-data/record-data is a resource cache for JSON:API structured data. It integrates with the store via the hookcreateRecordDataFor
- @ember-data/model is a presentation layer, it integrates with the store via the hooksinstantiateRecord and teardownRecord.
- @ember-data/adapter provides various network API integrations for APIS built over specific REST or JSON:API conventions.
- @ember-data/serializer pairs with@ember-data/adapter to normalize and serialize data to and from an API format into the JSON:API format understood by @ember-data/record-data.
- @ember-data/debug provides debugging support for theember-inspector.
- ember-data is a "meta" package which bundles all of these together for convenience

The packages interop with each other through well defined public API boundaries. The core
of 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
public APIs, other libraries or applications may provide their own implementations. For instance, ember-m3 is a commonly used presentation and cache implementation suitable for complex resource objects and graphs.

Configuration


Deprecation Stripping


EmberData allows users to opt-in and remove code that exists to support deprecated behaviors.

If 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.

  1. ```ts
  2. let app = new EmberApp(defaults, {
  3.   emberData: {
  4.     compatWith: '4.8',
  5.   },
  6. });
  7. ```


randomUUID polyfill


EmberData 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
the necessary feature if your browser support or deployment environment demands it. To
activate this polyfill:

  1. ```ts
  2. let app = new EmberApp(defaults, {
  3.   '@embroider/macros': {
  4.     setConfig: {
  5.       '@ember-data/store': {
  6.         polyfillUUID: true
  7.       },
  8.     },
  9.   },
  10. });
  11. ```

removing inspector support in production


If you do not want to ship inspector support in your production application, you can specify
that all support for it should be stripped from the build.

  1. ```ts
  2. let app = new EmberApp(defaults, {
  3.   emberData: {
  4.     includeDataAdapterInProduction: false
  5.   }
  6. });
  7. ```


Debugging


Many portions of the internals are helpfully instrumented with logging that can be activated
at build time. This instrumentation is always removed from production builds or any builds
that has not explicitly activated it. To activate it set the appropriate flag to true.

  1. ```ts
  2.   let app = new EmberApp(defaults, {
  3.     emberData: {
  4.       debug: {
  5.           LOG_PAYLOADS: false, // data store received to update cache with
  6.           LOG_OPERATIONS: false, // updates to cache remote state
  7.           LOG_MUTATIONS: false, // updates to cache local state
  8.           LOG_NOTIFICATIONS: false,
  9.           LOG_REQUEST_STATUS: false,
  10.           LOG_IDENTIFIERS: false,
  11.           LOG_GRAPH: false, // relationship storage
  12.           LOG_INSTANCE_CACHE: false, // instance creation/deletion
  13.       }
  14.     }
  15.   });
  16. ```

Contributing


See the Contributing guide for details.


License


This project is licensed under the MIT License.