aboutsummaryrefslogtreecommitdiffstats
path: root/core/cycle.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-03-03 10:52:39 +0000
committers-ol <s-ol@users.noreply.github.com>2020-03-05 10:36:22 +0000
commit13fdf952138454184f42f50e15c5c4974b2c7eed (patch)
tree56405051078b17766695cf4b1c659c8fd68d3035 /core/cycle.moon
parentdocument more interfaces (diff)
downloadalive-0.0.tar.gz
alive-0.0.zip
refactoring cyclic requiresv0.0
Diffstat (limited to 'core/cycle.moon')
-rw-r--r--core/cycle.moon26
1 files changed, 26 insertions, 0 deletions
diff --git a/core/cycle.moon b/core/cycle.moon
new file mode 100644
index 0000000..57d4a75
--- /dev/null
+++ b/core/cycle.moon
@@ -0,0 +1,26 @@
+-- late-resolve cyclic dependencies
+--
+-- this module provides a proxy for resolving values from modules which cannot
+-- be loaded due to cyclic dependencies. Instead of
+--
+-- import Something from require 'core.somewhere'
+-- Something ...
+--
+-- use
+--
+-- import somewhere from require 'core.cycle'
+-- somewhere.Something ...
+--
+-- Make sure cycle:load() is called before you access or dereference
+-- `somewhere`.
+
+load = =>
+ for name, module in pairs @
+ for k, v in pairs require "core.#{name}"
+ module[k] = v
+
+setmetatable {}, __index: (key) =>
+ return load if key == 'load'
+
+ with v = {}
+ rawset @, key, v