• Stars
    star
    368
  • Rank 115,958 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated about 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A framework for keeping your Ember.js apps in sync.

Ember.js Persistence Foundation

Build Status

Ember.js Persistence Foundation (epf) is a robust and stable framework for syncing client state with a persistent backend such as a REST API or socket connection. Defining characteristics of epf include:

  • Correctness is paramount. All other features, including performance, are important, but secondary.
  • Built around synchronization. Models are never locked and framework semantics assume updates are always coming in from a backend.
  • Full support for relationships. Related models can be saved concurrently and the framework will automatically order requests around foreign key dependencies.
  • Robust handling of conflicts and errors.
  • Forking models is first-class within the framework.
  • All operations are structured around javascript promises.

Epf is a functional alternative to ember-data and is used in production at GroupTalent with dozens of inter-related models.

Installation

For now, as epf is in development, follow the development instructions to use epf. The build-browser command will create browser-compatible distributables in the dist folder. Include epf.js in the page after ember.js.

Getting Started

Your backend

By default, epf assumes that the backend is a REST api which sticks to pretty much the same conventions as ember-data's RESTAdapter needs. There are a few differences however:

  • EPF sets a client_id in the JSON for every model and expects this to be echoed back by the server. It uses this to keep it's internal idmap up to date.
  • Related keys still need to use _id and _ids (this is different from ember-data 1.0 beta 2)

Defining Models

All models within epf are subclasses of Ep.Model. For example:

App.Post = Ep.Model.extend({
  title: Ep.attr('string'),
  body: Ep.attr('string'),

  comments: Ep.hasMany(App.Comment),
  user: Ep.belongsTo(App.User)
});

Loading Data

The primary means of interacting with epf is through a session. Epf automatically injects a primary session into all routes and controllers. To load data, you can use the load method on the session:

App.PostRoute = Ember.Route.extend({

  model: function(params) {
    return this.session.load('post', params.post_id);
  }

});

For compatibility with the behavior of the Ember.js router, a find method is also placed on models. The above code is equivalent to:

App.PostRoute = Ember.Route.extend({

  model: function(params) {
    return App.Post.find(params.post_id);
  }

});

The find method is the only method that is available on the models themselves and it is recommended to go through the session directly.

By default, Ember.js will automatically call the find method, so the above route can actually be simplified to:

App.PostRoute = Ember.Route.extend({
  // no model method required, Ember.js will automatically call `find` on `App.Post`
});

The session object also has other methods for finding data such as query.

Mutating Models

To mutate models, simply modify their properties:

post.title = 'updated title';

To persist changes to the backend, simply call the flush method on the session object.

post.title = 'updated title';
session.flush();

In epf, most things are promises. In the above example you could listen for when the flush has completed using the promise API:

post.title = 'updated title';
session.flush().then(function(models) {
  // this will be reached if the flush is successful
}, function(models) {
  // this will be reached only if there are errors
});

Handling Errors

Sessions can be flushed at any point (even if other flushes are pending) and re-trying errors is as simple as performing another flush:

post.title = 'updated title';
session.flush().then(null, function() {
  // the reject promise callback will be invoked on error
});

// do something here that should correct the error (e.g. fix validations)

session.flush(); // flush again

Models also have an errors property which will be populated when the backend returns errors.

Transactional Semantics and Forked Records

Changes can be isolated easily using child sessions:

var post = session.load(App.Post, 1);

var childSession = session.newSession(); // this creates a "child" session

var childPost = childSession.load(App.Post, 1); // this record instance is separate from its corresponding instance in the parent session

post === childPost; // returns false, they are separate instances
post.isEqual(childPost); // this will return true

childPost.title = 'something'; // this will not affect `post`

childSession.flush(); // this will flush changes both to the backend and the parent session, at this point `post` will have its title updated to reflect `childPost`

Development

To build epf, follow the instructions below:

  • Install node.
  • git clone https://github.com/getoutreach/epf
  • cd epf
  • npm install
  • npm test to run the tests via mocha
  • To build a browser distributable, run the build-browser command in the repository root with ember-script build-browser (make sure to install ember-script globally).

Discussion list

You can join the email discussion group to get help, as well as discuss new features and directions for Epf. Please post any questions, interesting things you discover or links to useful sites for Epf users.

More Repositories

1

adminjs

The backend agnostic administration framework.
JavaScript
701
star
2

localizer

โ›ต A no-frills local development tool for service developers working in Kubernetes
Go
128
star
3

active_model_serializers-cancan

CanCan support for AMS
Ruby
26
star
4

goql

A GraphQL client package written in Go.
Go
18
star
5

stencil

๐Ÿœ smart templating engine for service development
Go
16
star
6

embedded_associations

Rails gem to give controllers logic to handle embedded associations
Ruby
15
star
7

stacked

An open source icon set of technology logos
CSS
11
star
8

bullhorn-rest

Ruby wrapper for the Bullhorn REST API
Ruby
10
star
9

clientxtsdk

Repo containing source code of the SDK add-on creators use to create Outreach add-ons
TypeScript
9
star
10

devenv

Kubernetes powered developer environments
Go
9
star
11

gobox

A collection of go libraries
Go
9
star
12

devbase

A collection of scripts, makefile, etc that help create microservices
Shell
6
star
13

cjsx2jsx

Convert CJSX files to modern JSX
JavaScript
6
star
14

outreach-platform-sdk

The home of our platform API documentation, example code, and SDK.
Java
6
star
15

extensibility-sdk

Repo containing source code of the SDK add-on creators use to create Outreach applications
TypeScript
6
star
16

jsonnet-libs

Libraries to help simplify Outreach manifests
Jsonnet
5
star
17

actions

Github Actions framework for Go
Go
4
star
18

vcluster-fs-syncer

Disk synchronization for vclusters (https://www.vcluster.com/)
Go
3
star
19

stencil-golang

Template repository for Golang applications
Smarty
3
star
20

launchdarkly-js-extension-sdk

LaunchDarkly browser extension background service worker sdk
TypeScript
3
star
21

stencil-circleci

CircleCI configuration for stencil
Smarty
2
star
22

stencil-template-base

Stencil template repository for template repositories
Smarty
2
star
23

conrad

Ruby
2
star
24

stencil-base

Base templates for a stencil backed service
Smarty
2
star
25

getoutreach.github.io

Github pages site for Outreach Engineering
HTML
1
star
26

epf-website

Website for http://epf.io: Ember.js Persistence Foundation
Ruby
1
star
27

clientxtdocs

Repository containing documentation and samples for client extensibility sdk
1
star
28

threatstack-ruby

Ruby implementation of the Threatstack API
Ruby
1
star
29

broccoli-systemjs-builder

Broccoli system.js filter optimized for incremental rebuilds
JavaScript
1
star
30

adminjs-website

Website for Adminjs.com
JavaScript
1
star