Package Exports
- referencejs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (referencejs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Referencejs 
Referencejs manages references to values in plain JS or Immutable objects (called stores). You can use this to:
- Easily manage complex denormalized, without needing an explicited schema
- referencing data that doesn't exist yet (e.g. async data)
- normalize and denormalize immutable data
- Lazily denormalize stored data
Getting Started
Update a Plain store
import { createReference, resolveReference, dereference } from 'referencejs';
const jon = {
id: 'user_1',
name: 'John Doe',
email: 'jon@doe.com'
};
const jonRefrence = createReference('auth', 'users', jon.id);
let store = {};
store = resolveReference(store, jonReference, jon);
dereference(store, jonRefrence) === jon;Or use Immutable if that's your jam
import { Map, is } from 'immutable';
import { createReference, resolveReference, dereference } from 'referencejs/immutable';
const jon = Map({
id: 'user_1',
name: 'John Doe',
email: 'jon@doe.com'
});
const jonRefrence = createReference('auth', 'users', jon.id);
let store = Map();
store = resolveReference(store, jonReference, jon);
is(dereference(store, jonRefrence), jon);More Advanced: smartDereference
Dereferencing one reference at a time can be painful.
smartDereference scans an object or array and dereferences every reference it finds
import {
createReference,
smartDereference,
} from 'referencejs';
const store = {
users: {
user1: {
name: 'John Doe'
},
user2: {
name: 'Jane Doe'
},
user3: {
name: 'Billy Doe'
},
user4: {
name: 'Lucy Doe'
}
}
};
const john = createReference(['users', 'user1']);
const jane = createReference(['users', 'user2']);
const billy = createReference(['users', 'user3']);
const lucy = createReference(['users', 'user4']);
const familyTreeReferences = {
father: john,
mother: jane,
children: [billy, lucy]
};
// familyTree will contain the user objects instead of the references
const familyTree = smartDereference(store, familyTree);