Skip to content

Commit 2c79a70

Browse files
committed
🐛 Processing the child nodes of the newly added nodes
1 parent 3cc30bd commit 2c79a70

11 files changed

+28
-25
lines changed

dist/helpers/initAutoProcessor.d.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

dist/helpers/searchAndProcess.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { ILayouter } from './../layouter';
2+
declare const searchAndProcess: (layouter: ILayouter, context: Document | HTMLElement | Element) => Promise<unknown>;
3+
export default searchAndProcess;

dist/layouter.es.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/layouter.es.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/layouter.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/layouter.umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "layouter.js",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"description": "Layout builder without CSS, What???!!!",
55
"homepage": "https://layouter.io",
66
"main": "dist/layouter.umd.js",

src/helpers/mainObserver.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ILayouter } from './../layouter';
22
import { processors } from '../config/processors';
33
import getConfig from '../config/main';
4+
import searchAndProcess from './searchAndProcess';
45

56
const mainObserver = (layouter: ILayouter) => {
67
const config = getConfig();
@@ -17,6 +18,7 @@ const mainObserver = (layouter: ILayouter) => {
1718
if (Object.keys(props).length) {
1819
layouter.set(node, props);
1920
}
21+
searchAndProcess(layouter, node)
2022
}
2123
});
2224
} else if (mutation.type === 'attributes') {

src/helpers/initAutoProcessor.ts renamed to src/helpers/searchAndProcess.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { ILayouter } from './../layouter';
22
import { processors } from '../config/processors';
3-
import getConfig from '../config/main';
43

5-
const initAutoProcessor = (layouter: ILayouter) => {
4+
const searchAndProcess = (layouter: ILayouter, context: Document | HTMLElement | Element) => {
65
return new Promise((resolve) => {
7-
const config = getConfig();
86
const props = Object.keys(processors);
97
const attrs = props.map((prop) => `[${prop}]`).join(', ');
10-
const nodes = config.context.document.querySelectorAll(attrs);
11-
8+
const nodes = context.querySelectorAll(attrs);
129
if (!nodes.length) {
1310
resolve(layouter);
1411
return;
@@ -26,4 +23,4 @@ const initAutoProcessor = (layouter: ILayouter) => {
2623
});
2724
};
2825

29-
export default initAutoProcessor;
26+
export default searchAndProcess;

src/layouter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import reset from './methods/reset';
5656

5757
import { IStyles } from './helpers/createStyles';
5858
import { IBuildResult } from './methods/build';
59-
import initAutoProcessor from './helpers/initAutoProcessor';
59+
import searchAndProcess from './helpers/searchAndProcess';
6060
import mainObserver from './helpers/mainObserver';
6161
import { TDirectiveName } from './config/processors';
6262

@@ -268,7 +268,7 @@ const layouter = (
268268
};
269269

270270
// Auto init process
271-
initAutoProcessor(instance).then(() => {
271+
searchAndProcess(instance, context.document).then(() => {
272272
if (instance.ready) instance.ready(instance);
273273
mainObserver(instance);
274274
});

test/index.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ describe('Init', () => {
3434
})
3535
})
3636

37+
it('Adding a paragraph with child node', async () => {
38+
const paragraph = document.createElement('div');
39+
paragraph.innerHTML = '<span wdh="10">Spaneado</span>';
40+
document.body.appendChild(paragraph);
41+
await waitFor(() => {
42+
expect(screen.getByText('Spaneado')).toHaveClass('wdh-10')
43+
})
44+
})
45+
3746
it('Removing a Node from the DOM', async () => {
3847
const myDiv = document.createElement('div');
3948
myDiv.textContent = 'Content'
@@ -43,9 +52,4 @@ describe('Init', () => {
4352
expect(myDiv).not.toBeInTheDocument();
4453
})
4554
})
46-
47-
// it('Cheking if Layouter is attached in Window', () => {
48-
// console.log('window layouter: ', window.layouter);
49-
// expect(window).toHaveProperty('layouter');
50-
// })
5155
})

0 commit comments

Comments
 (0)