Skip to main content

SkipService<Inputs, ResourceInputs>

A Skip reactive service encapsulating a reactive computation.

A reactive Skip service is defined by a class implementing this SkipService interface.

Skip services operate over data organized into collections, each of which has a unique string name and associates keys to one or more values. The contents of collections are computed from initial data, other collections, or reactive or non-reactive external resources.

A Skip service's Inputs are collections that start populated with the initialData. The input collections is the mechanism by which a Skip service can accept writes. See runService for the write requests of the HTTP API, and SkipServiceBroker for the write operations of the method-call API.

It can be useful to think of the structure of a service's computation as a directed acyclic graph, the reactive computation graph, where the vertices are the named collections, and the edges are the functions (Mappers and Reducers) that produce collections from other collections. Part of the graph is structured in a way that is not dependent on the data or requests the service encounters at runtime: it is static. The rest of the graph is dynamic in the sense that collections/vertices are added in response to requests and data received at runtime by the service. The static portion of the graph is defined by createGraph, which receives the service's input collections. The result of createGraph is the boundary of the static reactive computation graph: named collections that are made available to the dynamic reactive computation graph as inputs to the instantiate computations of Resources.

Resources are the mechanism by which a service's collections are exposed to other services and clients for reading. A Resource implementation provides an instantiate function which is similar to createGraph but receives the boundary collections of the static reactive computation graph and only produces a single collection. The simplest Resources just return one of the collections they receive as an argument, thereby exposing a collection that would otherwise be internal to the service. Resources define the dynamic portion of the reactive computation graph that arises in response to requests and data at runtime, extending the static computation graph.

Resources are exposed by a SkipService implementation providing resources that associates resource names to Resource constructors. The interface involves class constructor functions for Resources since they are instantiated at runtime by the Skip framework in response to requests, using parameters provided as part of the request. When a SkipService receives a request, the corresponding Resource constructor is called with parameters obtained from the request, the resource object's instantiate function is called to produce a collection containing the results. Depending on the request, the requestor can read these results synchronously or subscribe to a stream of update events. Resource result collections are maintained up-to-date, with updates being reactively pushed to subscribers. See runService for the HTTP API for reading resources, and SkipServiceBroker for a method-call API.

Some of a Skip service's collections, those of type EagerCollection, are eagerly kept up-to-date by the framework. This includes the static portion of the reactive computation graph, so the static portion serves as pre-computed data that can be used by individual requests. The result collections produced by instantiating Resources are also eager and kept up-to-date. Note that this implies that the static portion of the reactive computation graph, as well as the results of resources, are eagerly updated when the service receives a write to an input collection. The computation of a Resource's output collection may use intermediate collections that are either eager or lazy. A lazy collection, of type LazyCollection, is one where the entries are only computed on-demand as a result of querying particular keys. Lazy collections memoize computations that are performed as part of computing the result of an update to an input of an eager collection. Lazy collections cannot be directly exposed as resources, but a couple auxiliary eager collections can be used to achieve the same effect.

Skip services can also make use of external services to compute their results. Within the bodies of SkipService.createGraph or Resource.instantiate, an external service can be accessed using Context.useExternalResource. Context.useExternalResource accepts the name of an external service, which must be associated to an instance of the ExternalService interface by the externalServices, as well as a resource the external service provides and parameters for it, and returns an eager collection of the contents of the resource provided by the external service. The resulting eager collection can then be incorporated into the reactive computation graph just like any other.

Type Parameters

Type ParameterDefault typeDescription
Inputs extends NamedCollectionsNamedCollectionsThe service's input collections.
ResourceInputs extends NamedCollectionsNamedCollectionsCollections provided to the resource computation by the service's createGraph.

Methods

createGraph()

createGraph(inputCollections, context): ResourceInputs

Build the static reactive computation graph by defining collections to be passed to resources.

Parameters

ParameterTypeDescription
inputCollectionsInputsThe service's input collections.
contextContextSkip Runtime internal state.

Returns

ResourceInputs

Reactive collections accessible to the resources.

Properties

externalServices?

optional externalServices: object;

External services that may be used by this service's reactive computation.

Index Signature

[name: string]: ExternalService

initialData?

optional initialData: InitialData<Inputs>;

Initial data for this service's input collections.

Remarks

While the initial data is not required to have a DepSafe type (only a subtype of Json is required); note that any modifications made to any objects passed as initialData will not be seen by a service once started.


resources

resources: object;

Reactive resources which constitute the public interface of this reactive service.

Index Signature

[name: string]: (params) => Resource<ResourceInputs>