Skip to content

Commit e96d8ed

Browse files
authored
Merge pull request #193 from AFASSoftware/mem
Memory optimisations - remove the oninput/-value wrapping
2 parents 1e71373 + 4ea68c2 commit e96d8ed

File tree

4 files changed

+4
-45
lines changed

4 files changed

+4
-45
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
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": "maquette",
3-
"version": "4.1.1",
3+
"version": "4.1.2",
44
"description": "Minimalistic Virtual DOM implementation with support for animated transitions.",
55
"homepage": "https://maquettejs.org/",
66
"keywords": [

src/projection.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,6 @@ let setProperties = (
231231
if (eventHandlerInterceptor) {
232232
propValue = eventHandlerInterceptor(propName, propValue, domNode, properties); // intercept eventhandlers
233233
}
234-
if (propName === "oninput") {
235-
(function () {
236-
// record the evt.target.value, because IE and Edge sometimes do a requestAnimationFrame between changing value and running oninput
237-
let oldPropValue = propValue;
238-
propValue = function (this: HTMLElement, evt: Event) {
239-
oldPropValue.apply(this, [evt]);
240-
(evt.target as any)["oninput-value"] = (evt.target as HTMLInputElement).value; // may be HTMLTextAreaElement as well
241-
};
242-
})();
243-
}
244234
}
245235
(domNode as any)[propName] = propValue;
246236
} else if (projectionOptions.namespace === NAMESPACE_SVG) {
@@ -443,13 +433,10 @@ let updateProperties = (
443433
let domValue = (domNode as any)[propName];
444434
if (
445435
domValue !== propValue && // The 'value' in the DOM tree !== newValue
446-
((domNode as any)["oninput-value"]
447-
? domValue === (domNode as any)["oninput-value"] // If the last reported value to 'oninput' does not match domValue, do nothing and wait for oninput
448-
: propValue !== previousValue) // Only update the value if the vdom changed
436+
propValue !== previousValue // Only update the value if the vdom changed
449437
) {
450438
// The edge cases are described in the tests
451439
(domNode as any)[propName] = propValue; // Reset the value, even if the virtual DOM did not change
452-
(domNode as any)["oninput-value"] = undefined;
453440
} // else do not update the domNode, otherwise the cursor position would be changed
454441
if (propValue !== previousValue) {
455442
propertiesUpdated = true;

test/dom/properties-tests.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -169,34 +169,6 @@ describe("dom", () => {
169169
});
170170

171171
describe("event handlers", () => {
172-
it("allows one to correct the value while being typed", () => {
173-
// Here we are trying to trim the value to 2 characters
174-
let typedKeys = "";
175-
let handleInput = (evt: Event) => {
176-
typedKeys = (evt.target as HTMLInputElement).value.substr(0, 2);
177-
};
178-
let renderFunction = () => h("input", { value: typedKeys, oninput: handleInput });
179-
let projection = dom.create(renderFunction(), {
180-
eventHandlerInterceptor: noopEventHandlerInterceptor,
181-
});
182-
let inputElement = projection.domNode as HTMLInputElement;
183-
expect(inputElement.value).to.equal(typedKeys);
184-
185-
// No correction
186-
inputElement.value = "ab";
187-
inputElement.oninput({ target: inputElement } as any);
188-
expect(typedKeys).to.equal("ab");
189-
projection.update(renderFunction());
190-
expect(inputElement.value).to.equal("ab");
191-
192-
// Correction kicking in
193-
inputElement.value = "abc";
194-
inputElement.oninput({ target: inputElement } as any);
195-
expect(typedKeys).to.equal("ab");
196-
projection.update(renderFunction());
197-
expect(inputElement.value).to.equal("ab");
198-
});
199-
200172
it("does not undo keystrokes, even if a browser runs an animationFrame between changing the value property and running oninput", () => {
201173
// Crazy internet explorer behavior
202174
let typedKeys = "";

0 commit comments

Comments
 (0)