Utilities that provide Evoke widgets context about the runtime environment.
Note: This package is included as part of the Evoke SDK. It is recommended to install the SDK instead.
npm install @evoke-platform/context
If your project was scaffolded using the plugin generator, then @evoke-platform/context
is already
available and no further installation is necessary.
Use ObjectStore
to work with objects and instances of objects. Obtain an object store with the useObject
hook:
const applications = useObject('application');
Hook for use in a functional component. Returns an instance of ObjectStore
for the specified object.
-
objectId
[string]- The id of the object you want to work with.
- Returns
ObjectStore
instance for the given object. Note there are no guarantees about whether the given object actually exists. If the specified object does not exist, failures will not occur until you try to use the object store.
This class enables you to perform operations on an object and its instances. Both promises and callbacks are supported. If a typical JavaScript callback function is provided as the last argument, the callback will be used to return the results. Otherwise, a promise is returned. For example:
function callback(err, result) {
if (err) {
// error occurred
} else {
// process result
}
}
applications.findInstances(callback);
-- or --
const results = await applications.findInstances();
ObjectStore includes built-in caching for object definitions with a 30-second time-to-live (TTL). This improves performance by reducing API calls for frequently accessed objects.
Get the object definition for this store's object. The returned object includes inherited properties and actions if this object is derived from another object. Results are cached for improved performance.
-
options
[object] - optional-
sanitized
[boolean]- If
true
, returns a sanitized version of the object reflecting only the properties and actions available to the current user.
- If
-
bypassCache
[boolean]- If
true
, bypasses the cache and forces a new API call. The cache is still updated with the results of the new API call.
- If
-
skipAlphabetize
[boolean]- If
true
, preserves the original order of properties instead of alphabetizing them (properties are alphabetized by default).
- If
-
Retrieves instances of the object that match the filter.
-
filter
[object] - optional-
fields
[array(string)] - optional- Object fields to be returned in the results. If not provided, all fields will be returned.
-
where
[object] - optional -
order
[array(string)] - optional -
skip
[number] - optional- If provided, skip the specified number of instances before returning results. Typically used together with
order
andlimit
.
- If provided, skip the specified number of instances before returning results. Typically used together with
-
limit
[number] - optional- If provided, limits the number of results to the specified count.
-
- Returns an array of matching instances.
Retrieves a specific instance of the object.
-
instanceId
[string]- ID of the instance to be retrieved.
Retrieves the history of an instance of the object.
-
instanceId
[string]- ID of the instance.
- Returns an array of history records.
Creates a new instance of the object.
-
input
[object]- Create action to be executed. The action must have
type = 'create'
.
- Create action to be executed. The action must have
- Returns newly created instance.
Performs an action on an existing instance.
-
input
[object]- Action to be executed. The action must not be a create action.
- Returns updated instance.
Invalidates cached data for this specific object ID and all its option variants. Use this when you know the object definition has changed on the server.
Static method that invalidates the entire object cache across all ObjectStore instances. Use this when you need to force fresh data for all objects.
Return the specified parameter value from the page route.
-
param
[string]- Parameter in the page route. For example, if the current page is
/applications/12345
matching the page route/applications/:instanceId
, then passing'instanceId'
will return'12345'
.
- Parameter in the page route. For example, if the current page is
- Returns the matched parameter's value from the current page's route, or
undefined
if the page does not have a matching parameter.
Returns an object with all of the current page's matched parameters, where the keys are the parameter names and the values are the corresponding parameter values.
Returns a function that can be used to navigate to another page. The returned function has the following signature:
function (page, params)
-
page
[string]- Page to navigate to. This can either be the exact route or a route template that includes parameter
placeholders (e.g. a page id). With the latter, use the
params
argument to specify the path parameters.
- Page to navigate to. This can either be the exact route or a route template that includes parameter
placeholders (e.g. a page id). With the latter, use the
-
params
[object] - optional- Key/value object mapping parameter names with their corresponding value. If
page
contains parameter placeholders, they will be replaced with corresponding values provided inparams
.
- Key/value object mapping parameter names with their corresponding value. If
Returns the currently loaded Evoke App as well as the following function.
-
findDefaultPageSlugFor
: An asynchronous function that takes anobjectId
as a parameter and returns the default page slug for that object, if no default page slug is found and the object is a subtype, the page slug of the first ancestor with a default page will be used. It returnsundefined
if no default page slug is found for any ancestor type.
Example usage:
const { id: appId, findDefaultPageSlugFor } = useApp();
const defaultPageSlug = await findDefaultPageSlugFor(objectId);
Hook used to obtain an instance of ApiServices
.
This class enables you to call the Evoke REST API. If the user is logged in to the Evoke platform, this class takes care of adding the appropriate authentication token to the API call.
Note: For accessing objects and instances, you can use ObjectStore instead.
This class is meant for use with the Evoke REST API, so any relative URLs provided are relative to the Evoke
environment's APIs, e.g. https://[environment-host]/api
. You can, however, call external APIs by providing an
absolute URL.
- useNofitication
-
useSignalRConnection (Deprecated)
- documentChanges (Deprecated)
- instanceChanges (Deprecated)
Hook used to obtain an instanceChanges instance and a documentChanges instance.
Subscribe to the specified object instance changes.
const { documentChanges } = useNotification();
documentChanges.subscribe('myObjectId', 'myInstanceId', (data) => {
console.log(data);
});
The data provided to the callback will be an array of DocumentChange
which contains the
following data:
-
objectId
- Object describing the instance associated with the updated document.
-
instanceId
- Instance that the updated document is associated with.
-
documentId
- Document that was updated.
-
type
- The type of update. Possible values are
BlobCreated
,BlobDeleted
, andBlobMetadataUpdated
.
- The type of update. Possible values are
Unsubscribe to the specified object instance changes.
Callback function is optional.
If callback function is not defined, all subscriptions will be removed.
If callback function is defined, you must pass the exact same Function instance as was previously passed to documentChanges.subscribe
.
Passing a different instance (even if the function body is the same) will not remove the subscription.
const { documentChanges } = useNotification();
const callback = (changes: DocumentChange[]) => {
console.log(changes);
};
documentChanges.subscribe('myObjectId', 'myInstanceId', callback);
documentChanges.unsubscribe('myObjectId', 'myInstanceId', callback);
Subscribe to the specified object changes.
const { instanceChanges } = useNotification();
instanceChanges.subscribe('myObjectId', (changes) => {
console.log(changes);
});
The data provided to the callback will be an array of InstanceChange
which contains the
following data:
-
objectId
- Object describing the instance associated with the updated document.
-
instanceId
- Instance that the updated document is associated with.
Unsubscribe to the specified object changes.
Callback function is optional.
If callback function is not defined, all subscriptions will be removed.
If callback function is defined, you must pass the exact same Function instance as was previously passed to instanceChanges.subscribe
.
Passing a different instance (even if the function body is the same) will not remove the subscription.
const { instanceChanges } = useNotification();
const callback = (changes: InstanceChange[]) => {
console.log(changes);
};
instanceChanges.subscribe('myObjectId', callback);
instanceChanges.unsubscribe('myObjectId', callback);
Deprecated This has been deprecated in favor of useNotification.
Hook used to obtain an instanceChanges instance of SignalRConnection
and a documentChanges instance of SignalRConnection
.
Deprecated This has been deprecated in favor of useNotification.
Subscribe to the specified object instance document changes.
const { documentChanges } = useSignalRConnection();
documentChanges.subscribe('myObjectId/myInstanceId', (data) => {
console.log(data);
});
The data provided to the callback will be an array of DocumentChange
which contains the
following data:
-
objectId
- Object describing the instance associated with the updated document.
-
instanceId
- Instance that the updated document is associated with.
-
documentId
- Document that was updated.
-
type
- The type of update. Possible values are
BlobCreated
,BlobDeleted
, andBlobMetadataUpdated
.
- The type of update. Possible values are
Deprecated This has been deprecated in favor of useNotification.
Unsubscribe to the specified object instance document changes.
Callback function is optional.
If callback function is defined, you must pass the exact same Function instance as was previously passed to documentChanges.subscribe
.
Passing a different instance (even if the function body is the same) will not remove the subscription.
const { documentChanges } = useSignalRConnection();
const callback = (data: DocumentChange[]) => {
console.log(data);
};
documentChanges.subscribe('myObjectId/myInstanceId', callback);
documentChanges.unsubscribe('myObjectId/myInstanceId', callback);
Deprecated This has been deprecated in favor of useNotification.
Subscribe to the specified object instance changes.
const { instanceChanges } = useSignalRConnection();
instanceChanges.subscribe('myObjectId', (instanceIds) => {
console.log(instanceIds);
});
The data provided to the callback will be an array of instance IDs that were updated.
Deprecated This has been deprecated in favor of useNotification.
Unsubscribe to the specified object instance changes.
Callback function is optional.
If callback function is defined, you must pass the exact same Function instance as was previously passed to instanceChanges.subscribe
.
Passing a different instance (even if the function body is the same) will not remove the subscription.
const { instanceChanges } = useSignalRConnection();
const callback = (instanceIds: InstanceChange[]) => {
console.log(instanceIds);
};
instanceChanges.subscribe('myObjectId', callback);
instanceChanges.unsubscribe('myObjectId', callback);