Comments (7)
Yeah, it crashes when you drag a function in to itself (or create any kind of circular dependency).
For my own reference, or if anyone wants to tackle it, here is a sketch for a fix:
Write a test that checks when you drag function A into function B that A does not contain B anywhere down the tree and B does not contain A anywhere down the tree.
Patch Actions.addChildFn to make sure that the above is not the case. If it is, don't add the function (and maybe display some sort of warning?).
from shadershop.
Thanks for the sketch. This seems to work doesn't account for the case of the added tree containing a compound function, I guess I'll get to that tomorrow:
containsCircularDep = (fn_to_add, existing) ->
if fn_to_add instanceof C.BuiltInFn
return false
fn_to_add = fn_to_add.childFns[0].fn
recurse = (fn) ->
if fn.__id == fn_to_add.__id
return true
if fn instanceof C.CompoundFn
fn.childFns.some recurse
else
false
recurse(existing)
Then in Actions.addChildFn, right before creating the new childFn,
if containsCircularDep fn, parent
console.log "CIRCULAR DEP"
return
What to do once the circular dependency is detected is up to you.
from shadershop.
Okay, I've got this version. Let me know if you can break it.
containsCircularDep = (fn_to_add, existing) ->
if fn_to_add instanceof C.BuiltInFn
return false
recurse = (fn) ->
if fn instanceof C.DefinedFn or fn instanceof C.CompoundFn
fn == existing or fn.childFns.some recurse
else if fn instanceof C.ChildFn
recurse fn.fn
else # C.BuiltInFn
false
recurse(fn_to_add)
The exact semantics are simple once stated: the function being add must not contain its soon-to-be parent anywhere in its tree.
from shadershop.
I like your wording. I pushed some code based on your snippet.
from shadershop.
I could have sworn there was a case that required handling C.DefinedFn
but I can't break your version. Thanks for merging.
from shadershop.
DefinedFn extends CompoundFn so that case handles it.
from shadershop.
Nice!
from shadershop.
Related Issues (14)
- There are 'compile' instructions but no 'run server' instructions HOT 2
- Not obvious how to delete my various test functions HOT 2
- Feature Idea: All the dimensions!
- What about audio?
- Undo/Redo HOT 3
- Domain Offline HOT 1
- Error: src\Actions.coffee isn't in the require path
- How to duplicate? HOT 2
- Demo redirects to spam site
- No gradation in colormap HOT 3
- Trying to re-order functions in Firefox deletes them HOT 1
- Add functions HOT 1
- License? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shadershop.