aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/init.moon158
-rw-r--r--app/test_component.moon212
-rw-r--r--app/todo.moon35
3 files changed, 0 insertions, 405 deletions
diff --git a/app/init.moon b/app/init.moon
deleted file mode 100644
index 8bc95e3..0000000
--- a/app/init.moon
+++ /dev/null
@@ -1,158 +0,0 @@
-require = relative ...
-
-union = (...) -> with res = {}
- c = 1
- for i = 1, select '#', ...
- tbl = select i, ...
- for val in *tbl
- res[c] = val
- c += 1
-
-map = (f, list) -> [f val for val in *list]
-
-patch_redirs = ->
- redirs =
- 'center-of-mass': 'center_of_mass',
- 'test-component': 'test_component',
- 'play-tags': 'tags',
-
- { :location } = window
- if (not location.search\find '=') and #location.search > 1
- name = location.search\sub 2
- location.href = redirs[name] or name
-
-client_goto = ->
- { :location } = window
- if module = location.search\match 'client=([%w_]+)'
- document.body.innerHTML = ''
- require "app.#{module}"
-
-articles = {
- {
- name: 'realities'
- desc: 'exploring the nesting relationships of virtual and other realities'
- },
- {
- name: 'mmmfs'
- desc: 'a file and operating system to live in (wip)'
- },
-}
-
-animations = {
- {
- name: 'twisted'
- desc: 'pseudo 3d animation'
- },
- {
- name: 'koch'
- desc: "lil' fractal thing"
- },
-}
-
-experiments = {
- {
- name: 'center_of_mass'
- desc: 'aligning characters by their centers of mass'
- },
- {
- name: 'tags'
- desc: 'organizing files with Functional Tags'
- },
-}
-
-meta = {
- {
- name: 'todo'
- desc: 'Todo MVC with the mmm UI framework'
- },
- {
- name: 'test_component'
- desc: 'test suite for the mmm reactive UI framework'
- },
-}
-
-content = {
- { 'articles', articles }
- { 'animations', animations }
- { 'experiments', experiments }
- { 'meta', meta }
-}
-
-index = {
- name: 'index'
- route: ''
- dest: 'index.html'
- render: =>
- import h1, h3, div, b, p, a, br, ul, tt, li, img from require 'lib.dom'
- import opairs from require 'lib.ordered'
-
- moon = '\xe2\x98\xbd'
-
- -- redirects for old-style URIs
- on_client patch_redirs
-
- iconlink = (href, src, alt, style) -> a {
- class: 'iconlink',
- :href,
- target: '_blank',
- img :src, :alt, :style
- }
-
- -- menu
- append h1 {
- style: {
- position: 'relative',
- 'border-bottom': '1px solid #000'
- },
- 'mmm',
- div {
- class: 'icons',
- iconlink 'https://github.com/s-ol/mmm', 'https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/github.svg',
- iconlink 'https://twitter.com/S0lll0s', 'https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/twitter.svg',
- iconlink 'https://webring.xxiivv.com/#random', 'https://webring.xxiivv.com/icon.black.svg', 'webring',
- { height: '0.9em', 'margin-left': '.04em' }
- }
- }
-
- append p {
- tt 'mmm'
- ' is not the '
- tt 'www'
- ', because it runs on '
- a { 'MoonScript', href: 'https://moonscript.org' }
- '.'
- br!
- 'You can find the source code of everything '
- a { 'here', href: 'https://github.com/s-ol/mmm' }
- '.'
- }
-
- for { category, routes } in *content
- append h3 category, style: { 'margin-bottom': '-.5em' }
- append ul for { :name, :desc, :route } in *routes
- li (a name, href: route), ': ', desc
-
- append p {
- "made with #{moon} by "
- a { 's-ol', href: 'https://twitter.com/S0lll0s' }
- }
-
- on_client client_goto
-}
-
-load = (module) -> require "app.#{module}"
-
-destify = (route) -> with route
- .route or= .name
- .dest or= "#{.route}/index.html"
-
- if .render == 'client'
- .render = -> on_client load, .name
- .render or= -> require '.' .. .name
-
-routes = map destify, union articles, animations, experiments, meta, { index }
-{
- :routes,
- indexed: { r.name, r for r in *routes }
- render: (name) -> require ".#{name}"
-}
diff --git a/app/test_component.moon b/app/test_component.moon
deleted file mode 100644
index d3f1489..0000000
--- a/app/test_component.moon
+++ /dev/null
@@ -1,212 +0,0 @@
-on_client ->
- import div, h1, ul, li, pre from require 'lib.dom'
-
- last = nil
- test_group = (name) ->
- if last
- append div (h1 name), ul last
-
- last = {}
- (name, test) ->
- ok, err = pcall test
- table.insert last, li if ok
- "passed '#{name}'"
- else
- "failed '#{name}'", pre err
-
- expect = (expected, note, ...) ->
- ok, msg = pcall ...
- print ok, msg\find expected
- if ok or not msg\find expected
- error note
-
- run_test = test_group 'component.moon'
-
- local ReactiveVar, ReactiveElement
- run_test "exports ReactiveVar, ReactiveElement", ->
- import ReactiveVar, ReactiveElement from require 'lib.component'
- assert ReactiveVar, "ReactiveVar not exported"
- assert ReactiveElement, "ReactiveElement not exported"
-
- run_test "exports tohtml helper", ->
- import tohtml from require 'lib.component'
- assert 'function' == (type tohtml), "tohtml not exported"
-
- run_test "exports append helper", ->
- import append from require 'lib.component'
- assert 'function' == (type append), "append not exported"
-
- run_test "exports text helper", ->
- import text from require 'lib.component'
- assert 'function' == (type text), "text not exported"
-
- node = text 'a test string'
- assert (js.instanceof node, js.global.Node), "expected text to generate a Node"
- assert node.data == 'a test string', "expected text to store the string"
-
- run_test "text joins multiple arguments", ->
- import text from require 'lib.component'
-
- node = text 'a', 'test', 'string'
- assert node.data == 'a test string', "expected text to join arguments with spaces"
-
- run_test "exports elements table", ->
- import elements from require 'lib.component'
-
- assert (type elements.div!) == 'table', "expected to build element with elements.div!"
- assert (type elements.madeup!) == 'table', "expected to build element with elements.madeup!"
-
- run_test = test_group 'ReactiveVar'
-
- run_test "stores a value", ->
- reactive = ReactiveVar 'test'
- assert 'test' == reactive\get!, "expected x to be 'test'"
-
- run_test "propagates updates", ->
- local done
-
- reactive = ReactiveVar 'test'
- reactive\subscribe coroutine.wrap (next) ->
- assert next == 'toast', "expected next to be 'toast'"
- assert coroutine.yield! == 'cheese', "expected next to be 'cheese'"
- done = true
-
- reactive\set 'toast'
- assert 'toast' == reactive\get!, "expected #get to return 'toast'"
- reactive\set 'cheese'
- assert done, "expected to reach the end"
-
- run_test "passed old value as well", ->
- local done
-
- reactive = ReactiveVar 1
- reactive\subscribe coroutine.wrap (next, last) ->
- assert last == 1, "expected last:1 to be 1"
- next, last = coroutine.yield!
- assert last == 2, "expected last:2 to be 2"
- done = true
-
- reactive\set 2
- reactive\set 3
- assert done, "expected to reach the end"
-
- run_test "provides transform shorthand", ->
- local done
-
- reactive = ReactiveVar 1
- reactive\subscribe coroutine.wrap (next, last) ->
- assert last == 1, "expected last:1 to be 1"
- next, last = coroutine.yield!
- assert last == 2, "expected last:2 to be 2"
- done = true
-
- add_one = (a) -> a + 1
- reactive\transform add_one
- reactive\transform add_one
- assert done, "expected to reach the end"
-
- run_test "#subscribe returns function to unsubscribe", ->
- calls = 0
-
- reactive = ReactiveVar 1
- unsub = reactive\subscribe coroutine.wrap () ->
- calls += 1
- coroutine.yield!
- calls += 1
- coroutine.yield!
- calls += 1
-
- assert 'function' == (type unsub), "expected to receive a function"
-
- reactive\set 2
- reactive\set 3
- assert calls == 2, "wat"
-
- unsub!
- reactive\set 4
- assert calls == 2, "expected to stop receiving updates"
-
- run_test "tracks multiple subscriptions at once", ->
- reactive = ReactiveVar 'test'
- unsub = reactive\subscribe coroutine.wrap (next) ->
- assert next == 'toast', "expected next to be toast"
- next = coroutine.yield!
- assert next == 'cheese', "expected next to be cheese"
- coroutine.yield!
- error "expected not to get here"
-
- reactive\set 'toast'
-
- local done
- reactive\subscribe coroutine.wrap (next) ->
- assert next == 'cheese', "expected next to be cheese"
- next = coroutine.yield!
- assert next == 'test', "expected next to be test"
- done = true
-
- reactive\set 'cheese'
- unsub!
- reactive\set 'test'
- assert done, "expected to reach the end"
-
- run_test = test_group 'ReactiveElement'
-
- run_test "creates a HTML element", ->
- elem = ReactiveElement 'span'
- assert elem.node and elem.node.localName == 'span', "expected Node to be a <span>"
-
- run_test "sets attributes from a table arg", ->
- elem = ReactiveElement 'span', class: 'never'
- assert elem.node.class == 'never', "expected class to be 'never'"
-
- run_test "appends Nodes from arguments", ->
- e_div, e_pre = div!, pre!
- elem = ReactiveElement 'span', e_div, e_pre
- assert elem.node.firstElementChild == e_div, "expected div to be the first child of elem"
- assert elem.node.lastElementChild == e_pre, "expected pre to be the last child of elem"
-
- run_test "can append ReactiveElements and text", ->
- e_div = ReactiveElement 'div'
- elem = ReactiveElement 'div', e_div, 'testtext'
- assert elem.node.firstElementChild == e_div.node, "expected div to be the first child of elem"
- assert elem.node.lastChild.data == 'testtext', "expected last child of elem to be 'testtext'"
-
- run_test "accepts attributes after children", ->
- e_div = div!
- elem = ReactiveElement 'div', e_div, class: 'test'
- assert elem.node.firstElementChild == e_div, "expected div to be the first child of elem"
- assert elem.node.class == 'test', "expected class to be 'test'"
-
- run_test "allows mixing attributes and children in a single table", ->
- e_div, e_pre = div!, pre!
- elem = ReactiveElement 'div', { class: 'test', e_div, e_pre }
- assert elem.node.firstElementChild == e_div, "expected div to be the first child of elem"
- assert elem.node.lastElementChild == e_pre, "expected pre to be the last child of elem"
- assert elem.node.class == 'test', "expected class to be 'test'"
-
- run_test "can unwrap and track attributes from ReactiveVars", ->
- klass = ReactiveVar 'test'
- elem = ReactiveElement 'div', class: klass
- assert elem.node.class == 'test', "expected class to be 'test'"
- klass\set 'toast'
- assert elem.node.class == 'toast', "expected class to be 'toast'"
-
- run_test "can unwrap and track children from ReactiveVars", ->
- child = ReactiveVar h1 'test'
- elem = ReactiveElement 'div', child, pre 'fixed'
- assert elem.node.firstElementChild.localName == 'h1', "expected first child to be h1"
- assert elem.node.childElementCount == 2, "expected node to have two children"
- child\set div 'toast'
- assert elem.node.firstElementChild.localName == 'div', "expected first child to be div"
- assert elem.node.childElementCount == 2, "expected node to have two children"
-
- run_test "warns when appending a string from a ReactiveVar", ->
- import text from require 'lib.component'
-
- str = ReactiveVar 'test'
- elem = ReactiveElement 'div', str
- expect 'cannot replace string node', 'expected error', str\set, 'string too'
- elem\destroy!
-
- elem = ReactiveElement 'div', str\map text
- str\set 'this is text'
diff --git a/app/todo.moon b/app/todo.moon
deleted file mode 100644
index f2baa50..0000000
--- a/app/todo.moon
+++ /dev/null
@@ -1,35 +0,0 @@
-on_client ->
- import ReactiveVar, append, text, elements from require 'lib.component'
- import div, form, span, h3, a, input, textarea, button from elements
-
- parent = div!
- todoItem = (desc, done) ->
- -- convert into reactive data sources
- desc, done = (ReactiveVar desc), ReactiveVar done
- with me = div style:
- margin: '8px'
- padding: '8px'
- background: '#eeeeee'
- \append h3 (desc\map text), style: 'margin: 0;'
- \append span done\map (done) -> text if done then 'done' else 'not done yet'
- \append input type: 'checkbox', checked: done, onchange: (e) => done\set e.target.checked
- \append a (text 'delete'), href: '#', onclick: (e) => parent\remove me
-
- parent\append todoItem 'write a Component System'
- parent\append todoItem 'eat Lasagna', true
-
- desc = ReactiveVar 'start'
- form = with form {
- action: ''
- style:
- margin: '2px'
- onsubmit: (e) =>
- e\preventDefault!
- parent\append todoItem desc\get!
- desc\set ''
- }
- \append input type: 'text', value: desc, onchange: (e) => desc\set e.target.value
- \append input type: 'submit', value: 'add'
-
- append parent
- append form