Extensions

Extensions #

Varv has four extension operators that can be used. While all four of them can be used in the "extensions" object in the root element of a concept definitions, when using the "extensions" object within a concept the "join" extension cannot be used. The following section will explain the use of each operator.

For all examples below we use the following base concepts, a "simpleTodo" concept with only a "label" property and a "completable" mixin that adds a property and an action:

{
    "concepts": {
        "simpleTodo": {
            "schema": { "label": "string" },
        },
        "completable": {
            "schema": { "completed": "boolean" },
            "actions": {
                "toggleCompleted": {
                    "when": { "click": "completable" },
                    "then": { "toggle": "completed" }
                }
            },
            "extensions": {
                // Possible extensions inside a concept
            }
        }
    },
    "extensions": [
        // Possible extensions outside a concept
    ]
}
Syntax Differences: Note that the syntax for extensions is slightly different depending on whether they are used inside or outside a concept.

"inject" Extension #

This operator takes one or multiple source concepts and one target concept, and injects the source concepts into the target concept, leaving the source concepts unaltered.

The following example injects the "completable" mixin into the "simpleTodo" concept and adds the formers schema and actions to it.

Outside of a concept:

{
    "concepts": {
        // ...
    },
    "extensions": [
        {
            "concept": "simpleTodo",
            "inject": "completable" // This can also take an array
        }
    ]
}

Inside a concept:

{
    "concepts": {
        "simpleTodo": {
            "extensions": {
                "inject": [ "completable" ]
            }
        }
    }
}

"join" Extension #

This operator takes two or more source concepts and merges their schema and actions, creating a new target concept. This operator cannot be used inside a concept.

The following example joins the "completable" and "simpleTodo" concepts into a new "completableTodo" concept.

Outside of a concept:

{
    "concepts": {
        // ...
    },
    "extensions": [
        {
            "join": [ "simpleTodo", "completable" ],
            "as": "completableTodo"
        }
    ]
}

"omit" Extension #

This operator takes an source concept and removes schema or actions from it.

The following example removes the "text" property from the "simpleTodo" concept. Actions could be removed in the same way.

Outside of a concept:

{
    "concepts": {
        // ...
    },
    "extensions": [
        {
            "concept": "simpleTodo",
            "omit": {
                "schema": [ "text" ]
            }
        }
    ]
}

Inside a concept:

{
    "concepts": {
        "simpleTodo": {
            "extensions": {
                "omit": {
                    "schema": [ "text" ],
                    "actions": []
                }
            }
        }
    }
}

"pick" Extension #

This operator takes an source concept and selects a subset of its schema and actions to create a new target concept, leaving the source concept unaltered.

The following example picks the property "text" from "completableTodo" (like the one created in earlier examples) and creates a new "newSimpleTodo" concept with only this property.

Outside of a concept:

{
    "concepts": {
        // ...
    },
    "extensions": [
        {
            "concept": "completableTodo",
            "pick": {
                "schema": [ "text" ],
                "actions": []
            },
            "as": "newSimpleTodo"
        }
    ]
}

Inside a concept:

{
    "concepts": {
        "newSimpleTodo": {
            "extensions": {
                "pick": [
                    {
                        "concept": "completableTodo",
                        "schema": [ "text" ],
                        "actions": []
                    }
                ]
            }
        }
    }
}

© 2023 Aarhus University | Made by cavi.au.dk | Contact Person: Clemens Nylandsted Klokmose