Define a patch source
In this tutorial, you will define a create a patch data source. You will
- define a writable
DictTypedata source to patch, and - define a patch source, and
- define a layout to interact with your patch source, and
- launch a solution, interact with and validate your datastream.
This lesson will assume that you have an empty project and asset which you can to deploy to a workspace named 06_01_02_define_a_patch_source with the following command:
edk template deploy -ycw 06_01_02_define_a_patch_source
Define a DictType data source
To define a DictType data source you will perform the following steps:
- define a datasource using a similar pattern as your previous
My Sourcedefinition. - set the type of the data source to
DictTypewith a compound value. - add the datasource to a template
In an asset, perform the above steps to create the resulting Typescript code:
import { SourceBuilder, Template } from "@elaraai/core"
const my_source = new SourceBuilder("My Source")
.value({
value: new Map([
["0", { value: 1n }],
["1", { value: 2n }],
])
})
export default Template(my_source)
Define a patch data source
To define a patch data source that will patch your My Source you will perform the following steps:
- define a second datasource called
My Patch. - set the type of the data source to
patchfrom the output data stream ofMy Source. - add the datasource to a template
In an asset, perform the above steps to create the resulting Typescript code:
import { SourceBuilder, Template } from "@elaraai/core"
const my_source = new SourceBuilder("My Source")
.value({
value: new Map([
["0", { value: 1n }],
["1", { value: 2n }],
])
})
const my_patch = new SourceBuilder("My Patch")
.patch(my_source.outputStream())
export default Template(my_source, my_patch)
Define a layout for interacting
To define a layout that allows you to iteract with your patch source, you will:
- create a new layout called
My Layout. - initialise a
panellayout and:- add a child
tablefrom the patch usingfromPatch - add a nested
panelcontaining:- a
tablefrom the output ofMy Source - another table from
writableStreamfromMy Patch, which contains the patches - another table from
conflictStreamfromMy Patch, which contains the conflicts
- a
- add a child
- add the datasource to a template
In an asset, perform the above steps to create the resulting Typescript code:
import { LayoutBuilder, SourceBuilder, Template } from "@elaraai/core"
const my_source = new SourceBuilder("My Source")
.value({
value: new Map([
["0", { value: 1n }],
["1", { value: 2n }],
])
})
const my_patch = new SourceBuilder("My Patch")
.patch(my_source.outputStream())
const my_layout = new LayoutBuilder("My Layout")
.panel('row', builder => builder
.table(50, "My Patch Table", builder => builder
.fromPatch(my_patch)
.columns()
)
.panel(50, 'column', builder => builder
.table(30, "My Source", builder => builder
.fromStream(my_source.outputStream())
.columns()
)
.table(40, "My Patches", builder => builder
.fromStream(my_patch.writeableStream())
)
.table(30, "My Conflicts", builder => builder
.fromStream(my_patch.conflictStream())
)
)
)
export default Template(my_source, my_patch, my_layout)
Build, deploy, and then navigate to the layout URL located within the tenant you deployed to see your layout:
workspaces/06_01_02_define_a_patch_source/layouts/My%20Layout/
Notice the effect to the tables, of:
- Editing rows in
My Patch Table - Adding rows in
My Patch Table - Deleting rows in
My Patch Table - Deleting rows in
My Sourceafter the above
You will notice that "My Patches" shows the individual patches being applied on top of My Source, you will also observe conflicts if you remove rows from My Source that have had if patches applied to them.
Example Solution
The final solution for this tutorial is available below:
In this module, you will learn about a new complex type, BlobType and how to use it.