mise 2.0.1 → 2026.5.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,78 +0,0 @@
1
- import { dom, component } from '../../src';
2
-
3
- window.requestAnimationFrame = setTimeout;
4
- describe('counter example', () => {
5
- let body;
6
- let count;
7
- let up;
8
- let down;
9
-
10
- beforeEach(() => {
11
- document.body.innerHTML = '';
12
-
13
- component({
14
- template: state => actions =>
15
- dom('div', null, [
16
-
17
- dom(
18
- 'span', {
19
- id: 'counter',
20
- },
21
- state.counter,
22
- ),
23
-
24
- dom('button', {
25
- id: 'up',
26
- onclick() {
27
- actions.increment();
28
- },
29
- }),
30
-
31
- dom('button', {
32
- id: 'down',
33
- onclick() {
34
- actions.decrement();
35
- },
36
- }),
37
- ]),
38
- state: {
39
- counter: 0,
40
- },
41
- actions: {
42
- increment: state => ({ counter: state.counter + 1 }),
43
- decrement: state => ({ counter: state.counter - 1 }),
44
- },
45
- });
46
-
47
- body = document.body;
48
- count = body.querySelector('#counter');
49
- up = body.querySelector('#up');
50
- down = body.querySelector('#down');
51
- });
52
-
53
- it('should load a counter', () => {
54
- expect(body).not.toBe('');
55
- });
56
-
57
- it('should have the proper initial state attached', () => {
58
- expect(count.innerHTML).toEqual('0');
59
- });
60
-
61
- it('should respond correctly to an increment action', (done) => {
62
- up.click();
63
-
64
- requestAnimationFrame(() => {
65
- expect(count.innerHTML).toEqual('1');
66
- done();
67
- });
68
- });
69
-
70
- it('should respond correctly to an decrement action', (done) => {
71
- down.click();
72
-
73
- requestAnimationFrame(() => {
74
- expect(count.innerHTML).toEqual('-1');
75
- done();
76
- });
77
- });
78
- });
@@ -1,211 +0,0 @@
1
- import { dom, component } from '../../src';
2
-
3
- window.requestAnimationFrame = setTimeout;
4
-
5
- const TodoItem = ({
6
- id, text, done, toggle, clear, create, remove, update,
7
- }) =>
8
- dom(
9
- 'li',
10
- {
11
- oncreate: create,
12
- onremove: remove,
13
- onupdate: update,
14
- },
15
- dom(
16
- 'span',
17
- {
18
- onclick: function onclick() {
19
- return toggle({ id });
20
- },
21
- style: done ? { userSelect: 'none', textDecoration: 'line-through' } : { userSelect: 'none' },
22
- },
23
- text,
24
- ),
25
- dom(
26
- 'span',
27
- {
28
- onclick: function onclick() {
29
- return clear({ id });
30
- },
31
- style: {
32
- marginLeft: '10px',
33
- color: 'red',
34
- },
35
- },
36
- 'x',
37
- ),
38
- );
39
-
40
- describe('counter example', () => {
41
- let body;
42
- let input;
43
- let add;
44
- let clear;
45
- let addTodo;
46
-
47
- beforeEach(() => {
48
- document.body.innerHTML = '';
49
-
50
- component({
51
- template: state => actions => (
52
- dom(
53
- 'div',
54
- null,
55
- dom(
56
- 'h1',
57
- null,
58
- 'Todos',
59
- ),
60
- dom(
61
- 'ul',
62
- {
63
- id: 'todos',
64
- className: 'todos',
65
- },
66
- state.todos.map(todo => dom(TodoItem, {
67
- create: function create() {
68
-
69
- },
70
- remove: function remove() {
71
- return function finish(done) {
72
- done();
73
- };
74
- },
75
- update: function update() {
76
- return function checkOldProps(oldProps) {
77
- //console.log(oldProps);
78
- };
79
- },
80
- text: todo.text,
81
- id: todo.id,
82
- done: todo.done,
83
- toggle: actions.toggle,
84
- clear: actions.remove,
85
- })),
86
- ),
87
- dom('input', {
88
- type: 'text',
89
- value: state.input,
90
- oninput: function oninput(e) {
91
- return actions.input({ value: e.target.value });
92
- },
93
- }),
94
- dom(
95
- 'button',
96
- {
97
- onclick: actions.add,
98
- id: 'add',
99
- },
100
- 'Add Todo',
101
- ),
102
- dom(
103
- 'button',
104
- {
105
- onclick: actions.clearTodos,
106
- id: 'clear',
107
- },
108
- 'Clear All Todos',
109
- ),
110
- )
111
- ),
112
- state: {
113
- todos: [],
114
- input: '',
115
- id: 0,
116
- },
117
- actions: {
118
- add: (state, actions) => {
119
- const text = state.input;
120
- actions.clearInput();
121
- return {
122
- todos: [
123
- ...state.todos,
124
- {
125
- text,
126
- id: state.id,
127
- done: false,
128
- },
129
- ],
130
- id: state.id + 1,
131
- };
132
- },
133
- input: (state, actions, { value }) => ({ input: value }),
134
- toggle: (state, actions, { id }) => ({
135
- todos: state.todos.map(todo => (
136
- todo.id === id ? { ...todo, done: !todo.done } : todo)),
137
- }),
138
- remove: (state, actions, { id }) => ({ todos: state.todos.filter(todo => todo.id !== id) }),
139
- clearInput: () => ({ input: '' }),
140
- clearTodos: () => ({ todos: [] }),
141
- },
142
- });
143
-
144
- body = document.body;
145
- input = body.querySelector('input');
146
- add = body.querySelector('#add');
147
- clear = body.querySelector('#clear');
148
-
149
- addTodo = (text = 'new todo') => {
150
- input.value = text;
151
-
152
- input.dispatchEvent(new Event('input'));
153
- add.click();
154
- };
155
- });
156
-
157
- it('should load', () => {
158
- expect(body).not.toBe('');
159
- });
160
-
161
- it('the initial state to not have any todos', () => {
162
- expect(body.querySelector('#todos').childNodes.length).toBe(0);
163
- });
164
-
165
- it('should add a todo', (done) => {
166
- addTodo();
167
-
168
- requestAnimationFrame(() => {
169
- expect(body.querySelector('#todos').childNodes.length).toBe(1);
170
- done();
171
- });
172
- });
173
-
174
- it('should clear the input after adding a todo', (done) => {
175
- addTodo();
176
-
177
- requestAnimationFrame(() => {
178
- expect(input.value).toBe('');
179
- done();
180
- });
181
- });
182
-
183
- it('should remove the todo', (done) => {
184
- addTodo();
185
-
186
- requestAnimationFrame(() => {
187
- body.querySelector('#todos span:last-child').click();
188
-
189
- requestAnimationFrame(() => {
190
- expect(body.querySelector('#todos').childNodes.length).toBe(0);
191
- done();
192
- });
193
- });
194
- });
195
-
196
- it('should remove all todos', (done) => {
197
- addTodo();
198
- addTodo();
199
- addTodo();
200
-
201
- requestAnimationFrame(() => {
202
- expect(body.querySelector('#todos').childNodes.length).toBe(3);
203
- clear.click();
204
-
205
- requestAnimationFrame(() => {
206
- expect(body.querySelector('#todos').childNodes.length).toBe(0);
207
- done();
208
- });
209
- });
210
- });
211
- });
@@ -1,12 +0,0 @@
1
- import 'jest';
2
- import * as tsExports from '../../src/index'
3
-
4
- describe('TypeScript exports', () => {
5
- it('should have a dom', () => {
6
- expect(tsExports.dom).toBeDefined();
7
- })
8
-
9
- it('should have a component', () => {
10
- expect(tsExports.component).toBeDefined();
11
- })
12
- })
@@ -1,55 +0,0 @@
1
- import { component, dom } from '../../src';
2
-
3
- window.requestAnimationFrame = setTimeout;
4
-
5
- describe('component tests', () => {
6
- beforeEach(() => {
7
- document.body.innerHTML = '';
8
-
9
- component({
10
- template: state => actions =>
11
- dom('div', null, [
12
- dom('span', { id: 'text' }, state.text),
13
- dom('button', { id: 'update', onclick() { actions.update(); } }),
14
- dom('button', { id: 'async', onclick() { actions.asyncUpdate(); } }),
15
- ]),
16
- state: {
17
- text: 'hello, world',
18
- },
19
- actions: {
20
- update: state => ({ text: `${state.text}!` }),
21
- asyncUpdate: state => (update) => {
22
- setTimeout(() => {
23
- update({ text: `${state.text}!!` });
24
- }, 500);
25
- },
26
- },
27
- });
28
- });
29
-
30
- it('should properly render', () => {
31
- expect(document.body.innerHTML).not.toEqual('');
32
- });
33
-
34
- it('should properly render the state', () => {
35
- expect(document.querySelector('#text').innerHTML).toEqual('hello, world');
36
- });
37
-
38
- it('should properly handle an update action', (done) => {
39
- document.querySelector('#update').click();
40
-
41
- requestAnimationFrame(() => {
42
- expect(document.querySelector('#text').innerHTML).toEqual('hello, world!');
43
- done();
44
- }, 500);
45
- });
46
-
47
- it('should handle a thunk', (done) => {
48
- document.querySelector('#async').click();
49
-
50
- requestAnimationFrame(() => {
51
- expect(document.querySelector('#text').innerHTML).toEqual('hello, world!!');
52
- done();
53
- }, 1000);
54
- });
55
- });
@@ -1,111 +0,0 @@
1
- import { dom } from '../../src/';
2
-
3
- describe('DOM jsx tests', () => {
4
- it('should be defined', () => {
5
- expect(dom).toBeDefined();
6
- });
7
-
8
- it('should properly handle a tag with no children or props', () => {
9
- const element = dom('main');
10
-
11
- expect(element).toEqual({
12
- type: 'main',
13
- props: {},
14
- children: [],
15
- });
16
- });
17
-
18
- it('should properly handle a tag with a null prop', () => {
19
- const element = dom('main', null);
20
-
21
- expect(element).toEqual({
22
- type: 'main',
23
- props: {},
24
- children: [],
25
- });
26
- });
27
-
28
- it('should properly handle a tag with children but no props', () => {
29
- const children = ['article', 'aside', 'section'];
30
- const element = dom('main', {}, ...children);
31
-
32
- expect(element).toEqual({
33
- type: 'main',
34
- props: {},
35
- children,
36
- });
37
- });
38
-
39
- it('should properly handle a tag with props but no children', () => {
40
- const props = {
41
- id: 'news',
42
- className: 'main-section',
43
- };
44
-
45
- const element = dom('main', props);
46
-
47
- expect(element).toEqual({
48
- type: 'main',
49
- props,
50
- children: [],
51
- });
52
- });
53
-
54
- it('should handle a child being a number', () => {
55
- const element = dom('li', {}, 0);
56
-
57
- expect(element).toEqual({
58
- type: 'li',
59
- props: {},
60
- children: ['0'],
61
- });
62
- });
63
-
64
- it('should properly handle children being an array', () => {
65
- const children = ['article', 'aside', 'section'];
66
- const element = dom('main', {}, children);
67
-
68
- expect(element).toEqual({
69
- type: 'main',
70
- props: {},
71
- children,
72
- });
73
- });
74
-
75
- it('should handle a function as a type', () => {
76
- const statelessComponent = (props, children) => dom('div', props, children);
77
- let element = dom(statelessComponent);
78
-
79
- expect(element).toEqual({
80
- type: 'div',
81
- props: {},
82
- children: [],
83
- });
84
-
85
- const props = { id: 'thing', className: 'thing-haver' };
86
- element = dom(statelessComponent, props);
87
-
88
- expect(element).toEqual({
89
- type: 'div',
90
- props,
91
- children: [],
92
- });
93
-
94
- const secondProps = { id: 'second-thing', className: 'thing-haver' };
95
- element = dom(statelessComponent, props, [
96
- dom(statelessComponent, secondProps, []),
97
- ]);
98
-
99
- expect(element).toEqual({
100
- type: 'div',
101
- props,
102
- children: [
103
- {
104
- type: 'div',
105
- props: secondProps,
106
- children: [],
107
- },
108
- ],
109
- });
110
- });
111
- });
@@ -1,26 +0,0 @@
1
- import { getUniques } from '../../src/utils';
2
-
3
- describe('get uniques', () => {
4
- it('should properly find the uniques', () => {
5
- const first = { a: '', b: '', c: '' };
6
- const second = { a: '', b: '', d: '' };
7
-
8
- const uniques = getUniques(first, second);
9
- expect(uniques.size).toBe(4);
10
- expect([...uniques.values()]).toEqual(['a', 'b', 'c', 'd']);
11
- });
12
-
13
- it('should handle undef/null as well', () => {
14
- const real = { a: '', b: '' };
15
- const fake = null;
16
-
17
- const first = getUniques(real, fake);
18
- const second = getUniques(fake, real);
19
-
20
- const set = new Set(['a', 'b']);
21
- expect(first).toEqual(set);
22
- expect(second).toEqual(set);
23
-
24
- expect(first).toEqual(second);
25
- });
26
- });
@@ -1,42 +0,0 @@
1
- /* eslint no-useless-escape: 0 */
2
-
3
- import { vdom } from '../../../src/vdom';
4
- import { dom } from '../../../src';
5
-
6
- const VDOM = vdom();
7
-
8
- describe('create element', () => {
9
- it('should create a simple text node', () => {
10
- const element = VDOM.createElement('hey');
11
-
12
- expect(element.nodeValue).toEqual('hey');
13
- });
14
-
15
- it('should create an empty div if no data is passed', () => {
16
- const element = VDOM.createElement(dom('h1'));
17
-
18
- expect(element.outerHTML).toEqual('<h1></h1>');
19
- });
20
-
21
- it('should make elements for the children, too', () => {
22
- const node = dom(
23
- 'ul',
24
- null,
25
- [
26
- dom('li', null, 'first'),
27
- dom('li', null, 'second'),
28
- dom('li', null, 'third'),
29
- ],
30
- );
31
-
32
- const element = VDOM.createElement(node);
33
-
34
- expect(element.outerHTML).toEqual('<ul><li>first</li><li>second</li><li>third</li></ul>');
35
- });
36
-
37
- it('should properly add props', () => {
38
- const element = VDOM.createElement(dom('div', { id: 'neato-element' }));
39
-
40
- expect(element.outerHTML).toEqual('<div id=\"neato-element\"></div>');
41
- });
42
- });
@@ -1,151 +0,0 @@
1
- /* eslint no-useless-escape: 0 */
2
-
3
- import { vdom } from '../../../src/vdom';
4
- import { dom } from '../../../src';
5
-
6
- const VDOM = vdom();
7
-
8
- describe('update', () => {
9
- let parent;
10
- beforeEach(() => {
11
- document.body.innerHTML = '';
12
- parent = document.body;
13
- });
14
-
15
- describe('creating an element', () => {
16
- it('should properly add an element if a previous one didnt exist', () => {
17
- VDOM.update(parent, null, null, dom('h1'));
18
-
19
- expect(parent.innerHTML).toEqual('<h1></h1>');
20
- });
21
-
22
- it('should try to run an oncreate function if it exists', () => {
23
- const create = jest.fn();
24
-
25
- VDOM.update(parent, null, null, dom('h1', { oncreate() { create(); } }));
26
-
27
- expect(create.mock.calls.length).toEqual(1);
28
- });
29
- });
30
-
31
- describe('removing an element', () => {
32
- it('should remove an element if a previous one did exist', () => {
33
- parent.innerHTML = '<h1></h1>';
34
-
35
- VDOM.update(parent, parent.childNodes[0], dom('h1'), null);
36
-
37
- expect(parent.innerHTML).toEqual('');
38
- });
39
-
40
- it('should try to run an onremove function if it exists', () => {
41
- const inner = jest.fn();
42
- const remove = () => inner;
43
-
44
- VDOM.update(parent, parent.childNodes[0], dom('h1', { onremove() { return remove(); } }), null);
45
-
46
- expect(inner.mock.calls.length).toEqual(1);
47
- });
48
- });
49
-
50
- describe('replacing an element', () => {
51
- it('should try to replace an element if the types are different', () => {
52
- parent.innerHTML = '<h1></h1>';
53
-
54
- VDOM.update(parent, parent.childNodes[0], dom('h1'), dom('h2'));
55
-
56
- expect(parent.innerHTML).toEqual('<h2></h2>');
57
- });
58
-
59
- it('should trigger an onupdate function if attempting to replace', () => {
60
- parent.innerHTML = '<h1></h1>';
61
-
62
- const inner = jest.fn();
63
- const replace = () => inner;
64
-
65
- VDOM.update(parent, parent.childNodes[0], dom('h1'), dom('h2', { onupdate() { return replace(); } }, []));
66
-
67
- expect(inner.mock.calls.length).toEqual(1);
68
- });
69
- });
70
-
71
- describe('updating an element in place', () => {
72
- it('should try to update a basic prop in place', () => {
73
- const previous = dom('h1');
74
- const next = dom('h1', { id: 'great' });
75
-
76
- parent.innerHTML = '<h1></h1>';
77
-
78
- VDOM.update(parent, parent.childNodes[0], previous, next);
79
-
80
- expect(parent.innerHTML).toEqual('<h1 id=\"great\"></h1>');
81
- });
82
-
83
- it('should try intelligently update a boolean value', () => {
84
- const previous = dom('h1');
85
- const next = dom('h1', { disabled: true, id: 'title' });
86
-
87
- parent.innerHTML = '<h1></h1>';
88
-
89
- VDOM.update(parent, parent.childNodes[0], previous, next);
90
-
91
- expect(parent.innerHTML).toEqual('<h1 disabled=\"true\" id=\"title\"></h1>');
92
- });
93
-
94
- describe('updating styles', () => {
95
- it('should try to add styles', () => {
96
- const previous = dom('h1');
97
- const next = dom('h1', { style: { fontSize: '18px' } });
98
-
99
- parent.innerHTML = '<h1></h1>';
100
-
101
- VDOM.update(parent, parent.childNodes[0], previous, next);
102
-
103
- expect(parent.innerHTML).toEqual('<h1 style=\"font-size: 18px;\"></h1>');
104
- });
105
-
106
- it('should try to swap styles properly', () => {
107
- const previous = dom('h1', { style: { textDecoration: 'line-through' } });
108
- const next = dom('h1', { style: { fontSize: '18px' } });
109
-
110
- parent.innerHTML = '<h1></h1>';
111
-
112
- VDOM.update(parent, parent.childNodes[0], previous, next);
113
-
114
- expect(parent.innerHTML).toEqual('<h1 style=\"font-size: 18px;\"></h1>');
115
- });
116
-
117
- it('should try to update style values if the property is the same', () => {
118
- const previous = dom('h1', { style: { fontSize: '20px' } });
119
- const next = dom('h1', { style: { fontSize: '18px' } });
120
-
121
- parent.innerHTML = '<h1></h1>';
122
-
123
- VDOM.update(parent, parent.childNodes[0], previous, next);
124
-
125
- expect(parent.innerHTML).toEqual('<h1 style=\"font-size: 18px;\"></h1>');
126
- });
127
-
128
- it('should try to remove styles properly', () => {
129
- const previous = dom('h1', { style: { textDecoration: 'line-through' } });
130
- const next = dom('h1');
131
-
132
- parent.innerHTML = '<h1></h1>';
133
-
134
- VDOM.update(parent, parent.childNodes[0], previous, next);
135
-
136
- expect(parent.innerHTML).toEqual('<h1></h1>');
137
- });
138
-
139
- it('should trigger an onupdate function when diffing props', () => {
140
- parent.innerHTML = '<h1></h1>';
141
-
142
- const inner = jest.fn();
143
- const replace = () => inner;
144
-
145
- VDOM.update(parent, parent.childNodes[0], dom('h1'), dom('h1', { onupdate() { return replace(); } }, []));
146
-
147
- expect(inner.mock.calls.length).toEqual(1);
148
- });
149
- });
150
- });
151
- });
package/tsconfig.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "removeComments": true,
4
- "allowJs": true,
5
- "allowSyntheticDefaultImports": true,
6
- "baseUrl": "./src"
7
- },
8
- "include": [
9
- "./src/index.d.ts"
10
- ],
11
- "awesomeTypescriptLoaderOptions": {
12
- "useBabel": true,
13
- "useCache": true
14
- }
15
- }