-
Notifications
You must be signed in to change notification settings - Fork 19
ReferenceContainer
JonathanMontane edited this page May 9, 2016
·
3 revisions
A ReferenceContainer component acts as a central component that lists all the References of an API. It stores each Reference in a ReferenceCache that acts as a helper to speed-up resolutions.
/* if in src/ */
import { ReferenceContainer } from './models/Core'
ReferenceContainer extends Immutable.Record using the following pattern:
class ReferenceContainer extends Immutable.Record({
cache: new Immutable.OrderedMap()
})
-
ReferenceContainer.cache
contains all the ReferenceCaches. We strongly advise against manipulating it directly. Use the class methods instead.
-
ReferenceContainer.set(uri, reference)
returns a new ReferenceContainer also containing the newuri
,reference
pair, where theReference
is stored in aReferenceCache
. If an equivalenturi
already exists in this ReferenceContainer, it will be replaced.
-
ReferenceContainer.get(uri, depth = 0)
returns the Reference corresponding to theuri
, resolved to thedepth
level.
-
ReferenceContainer.delete(uri)
returns a new ReferenceContainer without theuri
key in theReferenceContainer.cache
.
Please note that this example is abstract, and is there purely to represent the different interactions with ReferenceContainer
. The data may be non-sensical.
import references from './samples/references-examples'
import referenceCaches from './samples/reference-caches-examples'
import { ReferenceContainer } from './models/Core'
let container = new ReferenceContainer({
cache: new Immutable.OrderedMap({
'#/definitions/User': referenceCaches[0],
'#/definitions/Admin': referenceCaches[1],
})
})
container = container
.set('cache', new Immutable.OrderedMap({
'#/definitions/User': referenceCaches[1],
'#/definitions/Admin': referenceCaches[2],
}))
container = container
.set('#/definitions/Company', referenceCaches[0])
.delete('#/definitions/Company')
let resolvedReference = container.get('#/definitions/User', 3)