Hakushi.Rules (Hakushi v0.1.0)

Copy Markdown View Source

The rules of the edges of a canvas, the same in the browser and on the server.

<.canvas id="flow" graph={@graph} rules={[cycles: false]}>

While a person draws an edge, the browser shows the handles it may end on, and no others; when the edge comes to the server, the canvas checks the same rules again, so that a browser that does not follow them still makes no edge they forbid.

  • loops - an edge from a node to itself (false unless set).
  • duplicates - a second edge between the same two handles, in the same direction (false unless set).
  • cycles - an edge that closes a cycle, as a workflow must not have (true unless set).

A handle of one type connects to a handle that accepts it (see Hakushi.Components.handle/1). That rule is the browser's: the server does not know the handles, which are in the HEEx of each node. Check what an edge means for your app in on_change (see Hakushi.Change).

Summary

Types

Why the rules refuse an edge.

t()

Functions

Checks an edge against the rules, in a graph that does not have it yet.

Makes rules of a keyword list, or gives rules back.

Types

reason()

@type reason() :: :loop | :duplicate | :cycle

Why the rules refuse an edge.

t()

@type t() :: %Hakushi.Rules{
  cycles: boolean(),
  duplicates: boolean(),
  loops: boolean()
}

Functions

check(rules, graph, edge)

@spec check(t(), Hakushi.Graph.t(), Hakushi.Edge.t()) :: :ok | {:error, reason()}

Checks an edge against the rules, in a graph that does not have it yet.

new(rules)

@spec new(t() | keyword() | nil) :: t()

Makes rules of a keyword list, or gives rules back.