Skip to Main Content
Player Logo
PlayerPlugins

Check Path Plugin

The Check Path Plugin enables users to query segments of the view tree for contextual rendering or behavior. This is best suited to be referenced during the UI rendering phase, where one can make decisions about the rendering of an asset based on where it lies in the tree.

Usage

Install the plugin:
yarn add @player-ui/check-path-plugin
Add it to Player:
import CheckPathPlugin from '@player-ui/check-path-plugin';

const checkPathPlugin = new CheckPathPlugin();
const player = new Player({ plugins: [checkPathPlugin] });

// Start your flow
player.start(myFlow);
Then use the plugin to query the view:
const isCustomThing = checkPathPlugin.hasParentContext('my-asset-id', [
  'input',
  'myCustomViewType',
]);

API

Query

In most of the methods, the Query type is referenced. This can either be a function, string, or an object.
  • string - an alias for { type: '<string>' }
  • object - uses a partial-object match to query the object
  • function - a filter that gets passed an object, and returns a boolean
There are a few different functions exposed by the plugin you can use:

getParent

function getParent(id: string, query: Query | Query[]): Asset | undefined
The getParent method allows you to query up the tree, and return the first parent that matches the given query, or undefined. If an array is passed, the tree is parsed matching on each query item from left to right. The parent object that matches the last query item is returned.

getParentProp

function getParentProp(id: string): string | undefined
The getParentProp method returns the property on the parent object that the current object falls under. For example, an input with a text asset as the label, will return label for the parentProp of the text asset.

hasParentContext

function hasParentContext(id: string, query: Query | Query[]): boolean
Similar to getParent, the hasParentContext method responds with the existence of a parent with the given context.

hasChildContext

function hasChildContext(id: string, query: Query | Query[]): boolean
The compliment of hasParentContext, hasChildContext traverses down the tree for any path from the given node that satisfies the context requirements.