Skip to content

Commit

Permalink
[net] react
Browse files Browse the repository at this point in the history
- When we add a data into a place,
  try to fire all the neighboring transitions.
  • Loading branch information
xieyuheng committed Nov 17, 2023
1 parent aaec0fe commit 4549f03
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
9 changes: 3 additions & 6 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# net

[net] `react`
[net] react.test.ts

- when we add a data into a place,
all the neighboring transitions are checked for preparedness,
prepared transitions are executed
-- let's not handle non-deterministic for now.
[net] `transitionEntryFire` -- put input back on file

[net] transitionEntryPutOutputs -- error handling
[net] `transitionEntryPutOutputs` -- error handling

- task should have more information

Expand Down
4 changes: 2 additions & 2 deletions src/lang/net/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export * from "./Net"
export * from "./fireTransitionEntry"
export * from "./createNet"
export * from "./addPlace"
export * from "./addTransition"
export * from "./createNet"
export * from "./findPlaceEntry"
export * from "./findPlaceEntryOrFail"
export * from "./findTransitionEntry"
export * from "./findTransitionEntryOrFail"
export * from "./transitionEntryFire"
2 changes: 1 addition & 1 deletion src/lang/net/transitionEntryFire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TransitionEntry } from "./Net"

export type FiringResult = "Fired" | "NotFired" | "FiringError"

export async function fireTransitionEntry(
export async function transitionEntryFire(
transitionEntry: TransitionEntry,
): Promise<FiringResult> {
if (!transitionEntry.task) return "NotFired"
Expand Down
37 changes: 34 additions & 3 deletions src/lang/react/react.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
import { reactive } from "@vue/runtime-core"
import { Net } from "../net"
import { reactive, watch } from "@vue/runtime-core"
import { Net, PlaceEntry, transitionEntryFire } from "../net"

export function react(net: Net): void {
reactive
for (const [nodekey, placeEntry] of net.placeEntries) {
placeEntry.queue = reactive(placeEntry.queue)
reactivelyFireOutputTransitions(placeEntry)
}

initialAction(net)
}

async function initialAction(net: Net): Promise<void> {
for (const [nodeKey, transitionEntry] of net.transitionEntries) {
await transitionEntryFire(transitionEntry)
}
}

// When we add a data into a place,
// try to fire all the neighboring transitions.

function reactivelyFireOutputTransitions(placeEntry: PlaceEntry): void {
watch(
() => placeEntry.queue,
async () => {
if (placeEntry.queue.length > 0) {
for (const transitionEntry of placeEntry.outputTransitionEntries) {
const result = await transitionEntryFire(transitionEntry)
if (result === "Fired") return
}
}
},
{
deep: true,
},
)
}

0 comments on commit 4549f03

Please sign in to comment.