handle topology changes in the project

This commit is contained in:
Umur Ozkul 2022-08-26 02:01:27 +02:00
parent 0a8afc66a4
commit a8efd66fa3
2 changed files with 26 additions and 9 deletions

View File

@ -24,22 +24,35 @@ module Private = {
let createProject = () => { let createProject = () => {
let project: t = { let project: t = {
"tag": "reducerProject", "iAmProject": true,
"items": Belt.Map.String.empty, "items": Belt.Map.String.empty,
"stdLib": ReducerInterface_StdLib.internalStdLib, "stdLib": ReducerInterface_StdLib.internalStdLib,
"environment": InternalExpressionValue.defaultEnvironment, "environment": InternalExpressionValue.defaultEnvironment,
"previousRunOrder": [],
} }
project project
} }
let rec touchSource = (project: t, sourceId: string): unit => { let rec touchSource_ = (project: t, sourceId: string): unit => {
let item = project->getItem(sourceId) let item = project->getItem(sourceId)
let newItem = ProjectItem.touchSource(item) let newItem = ProjectItem.touchSource(item)
Belt.Map.String.set(project["items"], sourceId, newItem)->T.Private.setFieldItems(project, _) Belt.Map.String.set(project["items"], sourceId, newItem)->T.Private.setFieldItems(project, _)
touchDependents(project, sourceId)
} }
and touchDependents = (project: t, sourceId: string): unit => { and touchDependents = (project: t, sourceId: string): unit => {
let _ = getDependents(project, sourceId)->Belt.Array.forEach(_, touchSource(project, _)) let _ = getDependents(project, sourceId)->Belt.Array.forEach(_, touchSource_(project, _))
}
let touchSource = (project: t, sourceId: string): unit => {
touchSource_(project, sourceId)
touchDependents(project, sourceId)
}
let handleNewTopology = (project: t): unit => {
let previousRunOrder = project["previousRunOrder"]
let currentRunOrder = Topology.getRunOrder(project)
let diff = Topology.runOrderDiff(currentRunOrder, previousRunOrder)
Belt.Array.forEach(diff, touchSource(project, _))
T.Private.setFieldPreviousRunOrder(project, currentRunOrder)
} }
let getSource = (project: t, sourceId: string): option<string> => let getSource = (project: t, sourceId: string): option<string> =>
@ -73,7 +86,7 @@ module Private = {
let setContinues = (project: t, sourceId: string, continues: array<string>): unit => { let setContinues = (project: t, sourceId: string, continues: array<string>): unit => {
let newItem = project->getItem(sourceId)->ProjectItem.setContinues(continues) let newItem = project->getItem(sourceId)->ProjectItem.setContinues(continues)
Belt.Map.String.set(project["items"], sourceId, newItem)->T.Private.setFieldItems(project, _) Belt.Map.String.set(project["items"], sourceId, newItem)->T.Private.setFieldItems(project, _)
touchSource(project, sourceId) handleNewTopology(project)
} }
let getContinues = (project: t, sourceId: string): array<string> => let getContinues = (project: t, sourceId: string): array<string> =>
ProjectItem.getContinues(project->getItem(sourceId)) ProjectItem.getContinues(project->getItem(sourceId))
@ -81,7 +94,7 @@ module Private = {
let removeContinues = (project: t, sourceId: string): unit => { let removeContinues = (project: t, sourceId: string): unit => {
let newItem = project->getItem(sourceId)->ProjectItem.removeContinues let newItem = project->getItem(sourceId)->ProjectItem.removeContinues
Belt.Map.String.set(project["items"], sourceId, newItem)->T.Private.setFieldItems(project, _) Belt.Map.String.set(project["items"], sourceId, newItem)->T.Private.setFieldItems(project, _)
touchSource(project, sourceId) handleNewTopology(project)
} }
let getContinuation = (project: t, sourceId: string): ProjectItem.T.continuationArgumentType => let getContinuation = (project: t, sourceId: string): ProjectItem.T.continuationArgumentType =>
@ -113,6 +126,7 @@ module Private = {
let parseIncludes = (project: t, sourceId: string): unit => { let parseIncludes = (project: t, sourceId: string): unit => {
let newItem = project->getItem(sourceId)->ProjectItem.parseIncludes let newItem = project->getItem(sourceId)->ProjectItem.parseIncludes
Belt.Map.String.set(project["items"], sourceId, newItem)->T.Private.setFieldItems(project, _) Belt.Map.String.set(project["items"], sourceId, newItem)->T.Private.setFieldItems(project, _)
handleNewTopology(project)
} }
let rawParse = (project: t, sourceId): unit => { let rawParse = (project: t, sourceId): unit => {

View File

@ -3,17 +3,18 @@ module ExpressionT = Reducer_Expression_T
module ProjectAccessorsT = ReducerProject_ProjectAccessors_T module ProjectAccessorsT = ReducerProject_ProjectAccessors_T
@genType.opaque @genType.opaque
type project = {"tag": string} type project = {"iAmProject": bool}
//re-export //re-export
@genType @genType
type t = project type t = project
module Private = { module Private = {
type internalProject = { type internalProject = {
"tag": string, "iAmProject": bool,
"items": Belt.Map.String.t<ProjectItem.t>, "items": Belt.Map.String.t<ProjectItem.t>,
"stdLib": Reducer_Bindings.t, "stdLib": Reducer_Bindings.t,
"environment": ExpressionT.environment, "environment": ExpressionT.environment,
"previousRunOrder": array<string>,
} }
type t = internalProject type t = internalProject
@ -22,7 +23,9 @@ module Private = {
@set @set
external setFieldStdLib: (t, Reducer_Bindings.t) => unit = "stdLib" external setFieldStdLib: (t, Reducer_Bindings.t) => unit = "stdLib"
@set @set
external setFieldEnvironment: (t, ExpressionT.environment) => unit = "stdLib" external setFieldEnvironment: (t, ExpressionT.environment) => unit = "environment"
@set
external setFieldPreviousRunOrder: (t, array<string>) => unit = "previousRunOrder"
external castFromInternalProject: t => project = "%identity" external castFromInternalProject: t => project = "%identity"
external castToInternalProject: project => t = "%identity" external castToInternalProject: project => t = "%identity"