melody-idom
Advanced tools
Comparing version 1.0.4 to 1.1.0
@@ -56,3 +56,3 @@ /** | ||
'data-expanded': 'hello', | ||
}), | ||
}) | ||
); | ||
@@ -68,3 +68,3 @@ const el = container.childNodes[0]; | ||
'data-expanded': false, | ||
}), | ||
}) | ||
); | ||
@@ -82,3 +82,3 @@ const el = container.childNodes[0]; | ||
'data-expanded': undefined, | ||
}), | ||
}) | ||
); | ||
@@ -96,3 +96,3 @@ const el = container.childNodes[0]; | ||
'data-expanded': 'foo', | ||
}), | ||
}) | ||
); | ||
@@ -102,3 +102,3 @@ patch(container, () => | ||
'data-expanded': 'bar', | ||
}), | ||
}) | ||
); | ||
@@ -114,3 +114,3 @@ const el = container.childNodes[0]; | ||
'data-foo': 'foo', | ||
}), | ||
}) | ||
); | ||
@@ -120,3 +120,3 @@ patch(container, () => | ||
'data-bar': 'foo', | ||
}), | ||
}) | ||
); | ||
@@ -135,3 +135,3 @@ const el = container.childNodes[0]; | ||
'data-bar': 'bar', | ||
}), | ||
}) | ||
); | ||
@@ -141,3 +141,3 @@ patch(container, () => | ||
'data-bar': 'bar', | ||
}), | ||
}) | ||
); | ||
@@ -154,3 +154,3 @@ const el = container.childNodes[0]; | ||
'data-bar': 'bar', | ||
}), | ||
}) | ||
); | ||
@@ -161,3 +161,3 @@ patch(container, () => | ||
'data-bar': 'bar', | ||
}), | ||
}) | ||
); | ||
@@ -176,3 +176,3 @@ const el = container.childNodes[0]; | ||
'data-baz': 'baz', | ||
}), | ||
}) | ||
); | ||
@@ -183,3 +183,3 @@ patch(container, () => | ||
'data-baz': 'baz', | ||
}), | ||
}) | ||
); | ||
@@ -195,3 +195,3 @@ const el = container.childNodes[0]; | ||
'data-bar': 'bar', | ||
}), | ||
}) | ||
); | ||
@@ -208,3 +208,3 @@ expect(el.getAttribute('data-foo')).to.equal(null); | ||
'data-baz': 'baz', | ||
}), | ||
}) | ||
); | ||
@@ -216,3 +216,3 @@ patch(container, () => | ||
'data-baz': 'baz', | ||
}), | ||
}) | ||
); | ||
@@ -229,3 +229,3 @@ const el = container.childNodes[0]; | ||
'data-bar': 'bar', | ||
}), | ||
}) | ||
); | ||
@@ -243,3 +243,3 @@ expect(el.getAttribute('data-foo')).to.equal('foo'); | ||
'data-bar': 'bar', | ||
}), | ||
}) | ||
); | ||
@@ -254,2 +254,27 @@ patch(container, () => render({})); | ||
it('should add string event listeners', () => { | ||
let count = 0; | ||
const old = window.handler; | ||
window.handler = () => count++; | ||
patch( | ||
container, | ||
() => { | ||
elementVoid('button', 'test', null, 'onclick', 'handler();'); | ||
}, | ||
{} | ||
); | ||
const el = container.childNodes[0]; | ||
el.click(); | ||
patch( | ||
container, | ||
() => { | ||
elementVoid('button', 'test', null, 'onclick', undefined); | ||
}, | ||
{} | ||
); | ||
el.click(); | ||
expect(count).to.equal(1); | ||
window.handler = old; | ||
}); | ||
describe('for function attributes', () => { | ||
@@ -275,2 +300,25 @@ it('should not be set as attributes', () => { | ||
}); | ||
it('should remove event listeners', () => { | ||
let count = 0; | ||
const handler = () => count++; | ||
patch( | ||
container, | ||
() => { | ||
elementVoid('button', 'test', null, 'onclick', handler); | ||
}, | ||
{} | ||
); | ||
const el = container.childNodes[0]; | ||
el.click(); | ||
patch( | ||
container, | ||
() => { | ||
elementVoid('button', 'test', null, 'onclick', undefined); | ||
}, | ||
{} | ||
); | ||
el.click(); | ||
expect(count).to.equal(1); | ||
}); | ||
}); | ||
@@ -318,3 +366,3 @@ | ||
expect( | ||
el.getAttributeNS('http://www.w3.org/1999/xlink', 'href'), | ||
el.getAttributeNS('http://www.w3.org/1999/xlink', 'href') | ||
).to.equal('#foo'); | ||
@@ -321,0 +369,0 @@ }); |
@@ -27,2 +27,3 @@ /** | ||
getParent, | ||
options, | ||
} from '../src'; | ||
@@ -84,3 +85,3 @@ import { getChildren } from '../src/hierarchy'; | ||
}, | ||
{ text: 'Hello' }, | ||
{ text: 'Hello' } | ||
); | ||
@@ -99,3 +100,3 @@ expect(el.innerHTML).toEqual('<m-placeholder></m-placeholder>'); | ||
}, | ||
{ text: 'Hello' }, | ||
{ text: 'Hello' } | ||
); | ||
@@ -112,3 +113,3 @@ run(); | ||
}, | ||
{ text: 'Hello' }, | ||
{ text: 'Hello' } | ||
); | ||
@@ -125,3 +126,3 @@ run(); | ||
}, | ||
{ text: 'Hello' }, | ||
{ text: 'Hello' } | ||
); | ||
@@ -135,3 +136,3 @@ run(); | ||
}, | ||
{ text: 'Hello' }, | ||
{ text: 'Hello' } | ||
); | ||
@@ -151,3 +152,3 @@ expect(unmounted).toEqual(true); | ||
}, | ||
{}, | ||
{} | ||
); | ||
@@ -157,3 +158,3 @@ expect(el.innerHTML).toEqual('<m-placeholder></m-placeholder>'); | ||
expect(el.innerHTML).toEqual( | ||
'<section><div>Hello</div><div>World</div></section>', | ||
'<section><div>Hello</div><div>World</div></section>' | ||
); | ||
@@ -169,3 +170,3 @@ | ||
}, | ||
{}, | ||
{} | ||
); | ||
@@ -175,3 +176,3 @@ run(1); | ||
expect(el.innerHTML).toEqual( | ||
'<section><div>Hello</div><div>World</div></section>', | ||
'<section><div>Hello</div><div>World</div></section>' | ||
); | ||
@@ -181,3 +182,3 @@ run(1); | ||
expect(el.innerHTML).toEqual( | ||
'<section><div>hello</div><div>World</div></section>', | ||
'<section><div>hello</div><div>World</div></section>' | ||
); | ||
@@ -187,6 +188,47 @@ run(1); | ||
expect(el.innerHTML).toEqual( | ||
'<section><div>hello</div><div>universe</div></section>', | ||
'<section><div>hello</div><div>universe</div></section>' | ||
); | ||
}); | ||
it('should render synchronously', function() { | ||
// activate synchronous rendering option | ||
options.experimentalSyncDeepRendering = true; | ||
// initial rendering happens immediately | ||
patch( | ||
el, | ||
data => { | ||
component(ParentComponent, 'test', { | ||
firstChild: { text: 'Hello' }, | ||
secondChild: { text: 'World' }, | ||
}); | ||
}, | ||
{} | ||
); | ||
expect(el.innerHTML).toEqual('<m-placeholder></m-placeholder>'); | ||
run(1); | ||
expect(el.innerHTML).toEqual( | ||
'<section><div>Hello</div><div>World</div></section>' | ||
); | ||
patch( | ||
el, | ||
data => { | ||
component(ParentComponent, 'test', { | ||
firstChild: { text: 'hello' }, | ||
secondChild: { text: 'universe' }, | ||
}); | ||
}, | ||
{} | ||
); | ||
run(1); | ||
// updates outer element, first and second child component synchronously | ||
expect(el.innerHTML).toEqual( | ||
'<section><div>hello</div><div>universe</div></section>' | ||
); | ||
// deactivate synchronous rendering option | ||
options.experimentalSyncDeepRendering = false; | ||
}); | ||
it('should render new hierachies immediately', function() { | ||
@@ -201,7 +243,7 @@ patch( | ||
}, | ||
{}, | ||
{} | ||
); | ||
run(1); | ||
expect(el.innerHTML).toEqual( | ||
'<section><div>Hello</div><div>World</div></section>', | ||
'<section><div>Hello</div><div>World</div></section>' | ||
); | ||
@@ -222,3 +264,3 @@ }); | ||
}, | ||
{}, | ||
{} | ||
); | ||
@@ -228,3 +270,3 @@ run(1); | ||
expect(el.innerHTML).toEqual( | ||
'<section><div key="child1">Hello</div><div key="child2">World</div></section>', | ||
'<section><div key="child1">Hello</div><div key="child2">World</div></section>' | ||
); | ||
@@ -234,3 +276,3 @@ run(1); | ||
expect(el.innerHTML).toEqual( | ||
'<section><div>hello</div><div key="child2">World</div></section>', | ||
'<section><div>hello</div><div key="child2">World</div></section>' | ||
); | ||
@@ -240,3 +282,3 @@ run(1); | ||
expect(el.innerHTML).toEqual( | ||
'<section><div>hello</div><div>universe</div></section>', | ||
'<section><div>hello</div><div>universe</div></section>' | ||
); | ||
@@ -255,3 +297,3 @@ }); | ||
}, | ||
{}, | ||
{} | ||
); | ||
@@ -262,3 +304,3 @@ expect(el.innerHTML).toEqual('<m-placeholder></m-placeholder>'); | ||
expect(el.innerHTML).toEqual( | ||
'<section><div>Hello</div><div>World</div></section>', | ||
'<section><div>Hello</div><div>World</div></section>' | ||
); | ||
@@ -265,0 +307,0 @@ }); |
@@ -117,8 +117,8 @@ /** | ||
'span', | ||
'conditional', | ||
null, | ||
null, | ||
'id', | ||
'conditional-one', | ||
'data-foo', | ||
'foo', | ||
'foo' | ||
); | ||
@@ -129,3 +129,3 @@ elementVoid('span'); | ||
elementVoid('span', null, null, 'id', 'two'); | ||
elementVoid('span', 'last', null, 'id', 'two'); | ||
elementClose('div'); | ||
@@ -132,0 +132,0 @@ } |
@@ -137,17 +137,22 @@ /** | ||
else if (name[0] === 'o' && name[1] === 'n') { | ||
if (typeof value === 'function') { | ||
var useCapture = name !== (name = name.replace(/Capture$/, '')); | ||
name = name.toLowerCase().substring(2); | ||
if (typeof value === 'string') { | ||
applyAttributeTyped(el, name, value); | ||
} | ||
else { | ||
var eventName = name.replace(/Capture$/, ''); | ||
var useCapture = name !== eventName; | ||
eventName = eventName.toLowerCase().substring(2); | ||
if (value) { | ||
if (!attrs[name]) | ||
el.addEventListener(name, eventProxy, useCapture); | ||
if (!attrs[name]) { | ||
el.addEventListener(eventName, eventProxy, useCapture); | ||
} | ||
} | ||
else if (typeof attrs[name] === 'string') { | ||
el.removeAttribute(name); | ||
} | ||
else { | ||
el.removeEventListener(name, eventProxy, useCapture); | ||
el.removeEventListener(eventName, eventProxy, useCapture); | ||
} | ||
(el._listeners || (el._listeners = {}))[name] = value; | ||
(el._listeners || (el._listeners = {}))[eventName] = value; | ||
} | ||
else { | ||
applyAttributeTyped(el, name, value); | ||
} | ||
} | ||
@@ -154,0 +159,0 @@ else if (name !== 'list' && |
@@ -28,4 +28,6 @@ /** | ||
beforeUnmount?: (component) => void; | ||
/** Test synchronous loading of child components */ | ||
experimentalSyncDeepRendering?: boolean; | ||
}; | ||
declare const options: Options; | ||
export default options; |
@@ -20,2 +20,3 @@ /** | ||
import { debounce } from 'lodash'; | ||
import options from './options'; | ||
var supportsPassiveListeners = false; | ||
@@ -43,3 +44,3 @@ /* istanbul ignore next */ | ||
var prioritizationRequested = false; | ||
var prioritizationDisabled = false; | ||
var prioritizationDisabled = !!options.experimentalSyncDeepRendering; | ||
var NIL = { component: null, next: null }; | ||
@@ -244,3 +245,8 @@ var queue = NIL; | ||
queue = concat(queue, prevQueue); | ||
next = 0 < deadline.timeRemaining() ? pop() : null; | ||
if (options.experimentalSyncDeepRendering) { | ||
next = pop(); | ||
} | ||
else { | ||
next = 0 < deadline.timeRemaining() ? pop() : null; | ||
} | ||
} | ||
@@ -247,0 +253,0 @@ // notify the freshly mounted components |
@@ -17,3 +17,3 @@ /** | ||
*/ | ||
import { elementOpen as coreElementOpen, elementClose as coreElementClose, text as coreText, raw as coreRaw, currentComponent, } from './core'; | ||
import { elementOpen as coreElementOpen, elementClose as coreElementClose, text as coreText, raw as coreRaw, currentComponent, skip, } from './core'; | ||
import { updateAttribute } from './attributes'; | ||
@@ -197,2 +197,3 @@ import { getData } from './node_data'; | ||
elementOpen.apply(null, arguments); | ||
skip(); | ||
return elementClose(tag); | ||
@@ -199,0 +200,0 @@ }; |
@@ -1092,3 +1092,3 @@ 'use strict'; | ||
var prioritizationRequested = false; | ||
var prioritizationDisabled = false; | ||
var prioritizationDisabled = !!options.experimentalSyncDeepRendering; | ||
var NIL = { component: null, next: null }; | ||
@@ -1296,3 +1296,7 @@ var queue = NIL; | ||
queue = concat(queue, prevQueue); | ||
next = 0 < deadline.timeRemaining() ? pop() : null; | ||
if (options.experimentalSyncDeepRendering) { | ||
next = pop(); | ||
} else { | ||
next = 0 < deadline.timeRemaining() ? pop() : null; | ||
} | ||
} | ||
@@ -1493,13 +1497,18 @@ // notify the freshly mounted components | ||
} else if (name[0] === 'o' && name[1] === 'n') { | ||
if (typeof value === 'function') { | ||
var useCapture = name !== (name = name.replace(/Capture$/, '')); | ||
name = name.toLowerCase().substring(2); | ||
if (typeof value === 'string') { | ||
applyAttributeTyped(el, name, value); | ||
} else { | ||
var eventName = name.replace(/Capture$/, ''); | ||
var useCapture = name !== eventName; | ||
eventName = eventName.toLowerCase().substring(2); | ||
if (value) { | ||
if (!attrs[name]) el.addEventListener(name, eventProxy, useCapture); | ||
if (!attrs[name]) { | ||
el.addEventListener(eventName, eventProxy, useCapture); | ||
} | ||
} else if (typeof attrs[name] === 'string') { | ||
el.removeAttribute(name); | ||
} else { | ||
el.removeEventListener(name, eventProxy, useCapture); | ||
el.removeEventListener(eventName, eventProxy, useCapture); | ||
} | ||
(el._listeners || (el._listeners = {}))[name] = value; | ||
} else { | ||
applyAttributeTyped(el, name, value); | ||
(el._listeners || (el._listeners = {}))[eventName] = value; | ||
} | ||
@@ -1707,2 +1716,3 @@ } else if (name !== 'list' && name !== 'type' && name !== 'draggable' && !(el.ownerSVGElement || el.localName === 'svg') && name in el) { | ||
elementOpen$1.apply(null, arguments); | ||
skip(); | ||
return elementClose$1(tag); | ||
@@ -1709,0 +1719,0 @@ }; |
{ | ||
"name": "melody-idom", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -143,14 +143,18 @@ /** | ||
} else if (name[0] === 'o' && name[1] === 'n') { | ||
if (typeof value === 'function') { | ||
let useCapture = name !== (name = name.replace(/Capture$/, '')); | ||
name = name.toLowerCase().substring(2); | ||
if (typeof value === 'string') { | ||
applyAttributeTyped(el, name, value); | ||
} else { | ||
let eventName = name.replace(/Capture$/, ''); | ||
let useCapture = name !== eventName; | ||
eventName = eventName.toLowerCase().substring(2); | ||
if (value) { | ||
if (!attrs[name]) | ||
el.addEventListener(name, eventProxy, useCapture); | ||
if (!attrs[name]) { | ||
el.addEventListener(eventName, eventProxy, useCapture); | ||
} | ||
} else if (typeof attrs[name] === 'string') { | ||
el.removeAttribute(name); | ||
} else { | ||
el.removeEventListener(name, eventProxy, useCapture); | ||
el.removeEventListener(eventName, eventProxy, useCapture); | ||
} | ||
(el._listeners || (el._listeners = {}))[name] = value; | ||
} else { | ||
applyAttributeTyped(el, name, value); | ||
(el._listeners || (el._listeners = {}))[eventName] = value; | ||
} | ||
@@ -157,0 +161,0 @@ } else if ( |
@@ -28,2 +28,4 @@ /** | ||
beforeUnmount?: (component) => void; | ||
/** Test synchronous loading of child components */ | ||
experimentalSyncDeepRendering?: boolean; | ||
}; | ||
@@ -30,0 +32,0 @@ |
@@ -20,3 +20,3 @@ /** | ||
import { debounce } from 'lodash'; | ||
import options from './options'; | ||
interface Node { | ||
@@ -72,3 +72,3 @@ component: RenderableComponent; | ||
let prioritizationRequested = false; | ||
let prioritizationDisabled = false; | ||
let prioritizationDisabled = !!options.experimentalSyncDeepRendering; | ||
@@ -308,3 +308,8 @@ const NIL: Node = { component: null, next: null }; | ||
queue = concat(queue, prevQueue); | ||
next = 0 < deadline.timeRemaining() ? pop() : null; | ||
if (options.experimentalSyncDeepRendering) { | ||
next = pop(); | ||
} else { | ||
next = 0 < deadline.timeRemaining() ? pop() : null; | ||
} | ||
} | ||
@@ -311,0 +316,0 @@ // notify the freshly mounted components |
@@ -24,2 +24,3 @@ /** | ||
currentComponent, | ||
skip, | ||
} from './core'; | ||
@@ -234,2 +235,3 @@ import { updateAttribute } from './attributes'; | ||
elementOpen.apply(null, arguments); | ||
skip(); | ||
return elementClose(tag); | ||
@@ -236,0 +238,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
314375
8766
1