diff --git a/README.md b/README.md index eecb1e80..9c1f8f26 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ Declarative DOM tree composition, reusable components, reactive state binding - * Convert HTML snippet to **VanJS** code with our online [HTML to **VanJS** Converter](https://vanjs.org/convert) * Want server-side rendering? Check out [Mini-Van](https://github.com/vanjs-org/mini-van) (the entire vanjs.org site is built on top of Mini-Van) * For questions, feedback or general discussions, visit our [Discussions](https://github.com/vanjs-org/van/discussions) page +* [How did **VanJS** get its name?](https://vanjs.org/about#name) ## Support & Feedback diff --git a/src/van.js b/src/van.js index f25b9535..5eaa5a0e 100644 --- a/src/van.js +++ b/src/van.js @@ -1,22 +1,3 @@ -// Auto-Append feature -let _base; // Global element stores current insert position. If empty, elements are added at the end of document. -let _baseStack = []; // Stack for storing _base positions - -// set a new basepoint for append, save previous on baseStack -function begin(ID) { - _baseStack.push(_base);// Save old base - if (_baseStack.length > 100) throw new Error("_baseStackOverflow in begin()"); - - _base = (typeof (ID) === 'string') ? document.getElementById(ID) : ID - return _base -} -// restore last base, cnt: call multiple times -function end(cnt = 1) { - if (cnt > 1) end(cnt - 1) - if (_baseStack.length <= 0) throw new Error("_baseStack empty in end()") - return (_base = _baseStack.pop()) // restore old stack -} - // This file consistently uses `let` keyword instead of `const` for reducing the bundle size. // Aliasing some builtin symbols to reduce the bundle size. @@ -25,7 +6,7 @@ let Obj = Object, _undefined, protoOf = Object.getPrototypeOf let addAndScheduleOnFirst = (set, s, func, waitMs) => (set ?? (setTimeout(func, waitMs), new Set)).add(s) -let changedStates +let changedStates, ur let stateProto = { get "val"() { return this._val }, @@ -35,7 +16,7 @@ let stateProto = { let s = this, curV = s._val if (v !== curV) { if (s.oldVal === curV) - changedStates = addAndScheduleOnFirst(changedStates, s, updateDoms) + changedStates = addAndScheduleOnFirst(changedStates, s, updateDoms, ur) else if (v === s.oldVal) changedStates.delete(s) s._val = v @@ -74,9 +55,7 @@ let tags = new Proxy((name, ...args) => { else if (protoOf(v) === objProto) bind(...v["deps"], (...deps) => (setter(v["f"](...deps)), dom)) else setter(v) } - let r = add(dom, ...children) - if (_base) add(_base, r) // auto-Append, if base not empty - return r + return add(dom, ...children) }, {get: (tag, name) => tag.bind(_undefined, name)}) let filterBindings = s => s.bindings = s.bindings.filter(b => b.dom?.isConnected) @@ -110,5 +89,5 @@ let bind = (...deps) => { } return binding.dom } - -export default {add, tags, state, bind, begin, end} +let rate = (ms) => ur = ms +export default {add, tags, state, bind, rate}