forked from jashkenas/coffeescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a file and move some code upwards
- Loading branch information
1 parent
982b847
commit d370820
Showing
2 changed files
with
84 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
assert = require 'assert' | ||
|
||
|
||
class ProductRelations | ||
constructor: -> | ||
@in = new Set | ||
@out = new Set | ||
|
||
addInput: (taskId) -> | ||
assert (not @in.has taskId), taskId | ||
@in.add taskId | ||
|
||
addOutput: (taskId) -> | ||
assert (not @out.has taskId), taskId | ||
@out.add taskId | ||
|
||
|
||
class ProductRegistry | ||
constructor: -> | ||
@graph = new Map | ||
@knownTasks = new Map | ||
@knownContent = new Map | ||
|
||
ensureNewTask: (task) -> | ||
taskId = task.identifier() | ||
assert (not @knownTasks.has taskId), taskId | ||
@knownTasks.set taskId, task | ||
taskId | ||
|
||
maybeNewContent: (content) -> | ||
contentId = content.identifier() | ||
@knownContent.set contentId, content | ||
contentId | ||
|
||
setupRelations: (contentId) -> | ||
if @graph.has contentId | ||
return @graph.get contentId | ||
relations = new ProductRelations | ||
@graph.set contentId, relations | ||
relations | ||
|
||
registerTask: (task) -> | ||
taskId = @ensureNewTask task | ||
|
||
for {sources} in task.inputSources() | ||
for i in sources | ||
contentId = @maybeNewContent i | ||
relations = @setupRelations contentId | ||
relations.addInput taskId | ||
for {sources} in task.outputSources() | ||
for o in sources | ||
contentId = @maybeNewContent o | ||
relations = @setupRelations contentId | ||
relations.addOutput taskId |