Giter VIP home page Giter VIP logo

backbone-rel's Introduction

Build Status Dependency Status npm version

References vs. Embeddings

backbone-rel extends Backbone by two concepts that allow applications to model relationships between models: references and embeddings. These concepts are inspired by the MongoDB data modeling in terms of embedded and referenced documents (http://docs.mongodb.org/manual/core/data-modeling-introduction/).

References

A reference describes a relationship between two model classes (A and B) in terms of a unidirectional link or pointer from one instance of A to one or many instances of B. The reference is defined on the referencing object using the ID of the referenced object.

var User = Backbone.Model.extend({});

var LikeCollection = Backbone.Collection.extend({
	model: Like
});

var Comment = Backbone.Model.extend({
	references: {
		author: User,           // to-one reference
		likes: LikeCollection	// to-many reference
	}
});

References work especially well in conjunction with https://github.com/disqus/backbone.uniquemodel. If you set up a reference to a model class tracked by backbone.uniquemodel, a referenced model instance will automatically be resolved to the right instance in the unique model cache.

var User = UniqueModel( Backbone.Model.extend({}), "User" );

var Comment = Backbone.Model.extend({
	references: {
		author: User
	}
});
var user = new User({ id: 1, name: "John Doe" });
var comment = new Comment({ authorId: 1 });
assert(comment.get("user") === user);  // the referenced author has been resolved to the unique user instance

Embeddings

An embedded object lives in its parent.

  • The URL for the API endpoint of the embedded object is built based on the parent model's URL by appending the embedded object's "urlSuffix" property.

  • Alternatively, the embedded object can be managed entirely through its parent, meaning that it does not have a dedicated URL endpoint but its JSON representation is inlined in the parent JSON.

var MetaData = Backbone.Model.extend({});

var CommentCollection = Backbone.Collection.extend({
	model: Comment
});

var Post = Backbone.Model.extend({
	embeddings: {
		meta: MetaData,				// to-one embedding
		comments: CommentCollection // to-many embedding
	}
})

Embedding Models

Embedding Collections

Auto-fetching

This can be deactivated using the "autoFetchRelated"

  • Upon assigning a reference, the referenced model is automatically fetched from the server if it has never been synced before.

Side-loading

  • Side-loading referenced models' data is supported by nesting the JSON representation of the referenced object like this:

backbone-rel's People

Contributors

frontendphil avatar jfschwarz avatar par-vathy avatar renovate-bot avatar workflow-bot avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

isabella232

backbone-rel's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm karma-phantomjs-launcher Unavailable

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Update dependency chai-react to v4
  • Update dependency karma-coverage to v2
  • Update dependency karma-junit-reporter to v2
  • Update dependency karma-mocha to v2
  • Update dependency mocha to v10
  • Update dependency sinon to v18
  • Update dependency sinon-chai to v4
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • underscore >=1.5.0
  • backbone >=1.1.2
  • backbone.uniquemodel 0.9.0
  • chai 1.10.0
  • chai-react 3.0.1
  • docco 0.7.0
  • es5-shim 4.5.13
  • jquery 3.2.1
  • karma 0.13.22
  • karma-coverage 1.1.2
  • karma-junit-reporter 1.2.0
  • karma-mocha 1.3.0
  • karma-phantomjs-launcher 0.2.3
  • karma-requirejs 1.1.0
  • mocha 5.2.0
  • react 0.13.3
  • requirejs 2.3.5
  • rquery 2.0.9
  • sinon 1.17.7
  • sinon-chai 2.14.0
  • uglify-js 3.4.4

  • Check this box to trigger a request for Renovate to run again on this repository

Collection#set empties embedded collection in existing embeddings of the item models

Example:

trigger/form:

{
  "fields" : [ {
    "binding" : {
      "variableId" : "54dc644bd4c60b5eda1b05a0"
    },
    "id" : "54dc644bd4c60b5eda1b059f"
  } ]
}

process item in /processes collection:

{
  "id" : "54dc6441d4c60b5eda1b0592",
  "trigger" : {
    "type" : "form"
  }
}

Setting the process item through a collection fetch after the form has been loaded, empties the fields collection of the existing form. Still to research whether this also happens when just setting directly on the single process model.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Preset name not found within published preset config (monorepo:angularmaterial). Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.