Skip to content

Features

Queen Belle Dela Cruz edited this page Aug 8, 2024 · 5 revisions

History State

Without DevTools

Outside of the devtools, in order to observe changes in the history state, developers would have to check Rapid's context via the console.

The following accesses Rapid's history under the EditSystem.

> editor = rapidContext.systems.editor
EditSystem {_events: Events, _eventsCount: 5, context: Context, id: 'editor', dependencies: Set(4), …}
> editor.history
(8) [Edit, Edit, Edit, Edit, Edit, Edit, Edit, Edit]

Entities

Entities in history are represented by certain identifiers.

  • Entities starting with w are ways, which can represent either lines or areas.
  • Entities starting with n are nodes, which represent points within an area.

Entities with identifiers excluding a dash (-) are entities originally retrieved from OpenStreetMap.

Entities with identifiers including a dash (-) are entities created in Rapid.

Inspecting these entities, requires us to look deeper into the history object. Below is an example of inspecting changes in an area.

> editor.history[6].graph.entity('w-3').nodes
 ['n-9', 'n-10', 'n-11', 'n-9']

> editor.history[7].graph.entity('w-3').nodes
 ['n-9', 'n-10', 'n-11', 'n-12', 'n-9']

> editor.history[8].graph.entity('w-3').nodes
 ['n-9', 'n-10', 'n-11', 'n-12', 'n-13', 'n-9']

> editor.history[6].graph.entity('w-3').nodes
 ['n-9', 'n-10', 'n-11', 'n-9']

Difference Method

The EditSystem also has a Difference class, which returns the difference between base and stable states.

The Difference method can be found in Rapid's source code under modules > core > lib > Difference.js

> d = new Rapid.Difference(editor.history[5].graph, editor.history[6].graph)
Difference {_base: _Graph, _head: _Graph, _changes: Map(4), didChange: {…}}

Various methods in the Difference class can be used to compare any 2 graphs.

d.summary()
Map(1) {'w-2' => {…}}[[Entries]]0: {"w-2" => Object}key: "w-2"value: changeType: "deleted"entity: osmWay {tags: {…}, nodes: Array(6), id: 'w-2', v: 720, visible: true}graph: _Graph {_base: {…}, _local: {…}, _transients: Map(6), _childNodes: Map(0), _frozen: true}[[Prototype]]: Objectsize: 1[[Prototype]]: Map
d.deleted()
(6) [osmNode, osmNode, osmWay, osmNode, osmNode, osmNode]
d.modified()
[]length: 0[[Prototype]]: Array(0)
d.created()
[]

With DevTools

Using the DevTools, changes between each state can instead be viewed instantly in a panel without having to manually inspect Rapid's context. image

Clone this wiki locally