Skip to content

Commit

Permalink
#36 stable reordering in node_map
Browse files Browse the repository at this point in the history
  • Loading branch information
L3P3 committed Aug 29, 2021
1 parent 9125de7 commit ce79185
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ When I was introduced to [React](https://github.com/facebook/react), I liked it

- About **6k** code size (~3k compressed)
- **Stateful components** using [hooks](https://reactjs.org/docs/hooks-intro.html)
- **Compatible** with ancient browsers
- Optional **development mode**
- **Animations** integrated
- CSS-less **Animations** integrated
- **Fast and efficient**
- Conditional css classes on elements
- Not terribly inefficient
- Can be bundled together with your application
- 0 dependencies
- Production ready (at least the dynamic variant)
- No toolchain neccessary
- [RequireJS](https://requirejs.org) compatible
- [Production ready](https://softwareengineering.stackexchange.com/questions/61726)
- Compatible with down to 20th century browsers, basic polyfills included
- Created and actively maintained by a [perfectionist](https://www.webdesignerdepot.com/2010/04/the-ups-and-downs-of-being-a-perfectionist)

## Demos

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lui",
"version": "1.1.1",
"version": "1.1.2",
"description": "web framework",
"homepage": "https://l3p3.de/dok/lui.html",
"repository": {
Expand Down
26 changes: 13 additions & 13 deletions src/lui.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ let current_slots_index = 0;
let render_time = 0;

/**
animation frame request (or null)
pending animation frame request or 0
@type {number}
*/
let rerender_requested = 0;
Expand Down Expand Up @@ -512,6 +512,7 @@ const deps_comp_get = deps => (
const instance_render = (dom_parent, dom_first) => {
const instance = /** @type {TYPE_INSTANCE} */ (current);
const dom_after = dom_first;
const ilevel = instance.ilevel + 1;
current_slots = instance.slots;
current_slots_index = 1;

Expand Down Expand Up @@ -605,7 +606,7 @@ const instance_render = (dom_parent, dom_first) => {
object_comp_get(child_call.props)
),
iparent: instance,
ilevel: instance.ilevel + 1,
ilevel,
parent_index: childs_index,
slots: [],
childs: null_,
Expand Down Expand Up @@ -700,6 +701,7 @@ const instance_render = (dom_parent, dom_first) => {
);

let items_index = list_data.length;
let props_changed = true_;

if(
hook_prev(items_index, items_index) + items_index <= 0
Expand All @@ -713,14 +715,15 @@ const instance_render = (dom_parent, dom_first) => {
items_index > 0 &&
list_data_index(list_data, items_map, items_order)
);
const indexes_removed = [];

This comment has been minimized.

Copy link
@L3P3

L3P3 Aug 29, 2021

Author Owner

Whoops, forgot to remove it while fiddling.

DEBUG && (
items_index ||
hook_static()
);

// rerender?
if (state.item_map) {
state.props_changed = (
props_changed = (
props !== null_ &&
state.props_comp(
props,
Expand All @@ -730,7 +733,7 @@ const instance_render = (dom_parent, dom_first) => {

VERBOSE &&
props &&
state.props_changed &&
props_changed &&
log('props changed', object_diff(state.props_prev, props));

// remove items
Expand All @@ -757,10 +760,9 @@ const instance_render = (dom_parent, dom_first) => {
state.props_comp = (
state.props_prev = props
) && object_comp_get(props);
state.props_changed = true_;
}

// insert/reinsert all items
// for all items
const childs = instance.childs = new Array_(items_index);
while (items_index > 0) {
const key = items_order[--items_index];
Expand All @@ -783,7 +785,7 @@ const instance_render = (dom_parent, dom_first) => {
},
props_comp: null_,
iparent: instance,
ilevel: instance.ilevel + 1,
ilevel,
parent_index: items_index,
slots: [],
childs: null_,
Expand All @@ -808,13 +810,10 @@ const instance_render = (dom_parent, dom_first) => {
);
}
else {
if (child.parent_index !== items_index) {
instance_reinsert(child, dom_parent, dom_first);
child.parent_index = items_index;
}
instance_reinsert(child, dom_parent, dom_first);

if (
state.props_changed ||
props_changed ||
items_objects &&
state.item_comp(
items_map[key],
Expand All @@ -837,11 +836,12 @@ const instance_render = (dom_parent, dom_first) => {
}

(
childs[items_index] = child
childs[child.parent_index = items_index] = child
).dom_first && (
dom_first = child.dom_first
);
}

instance.dom_first =
dom_first !== dom_after
? dom_first
Expand Down

0 comments on commit ce79185

Please sign in to comment.