Skip to content

Commit

Permalink
Address some of Godfrey's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chadhietala committed Jun 21, 2017
1 parent c05bc54 commit b58d4d7
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/@glimmer/runtime/lib/dom/helper.ts
Expand Up @@ -125,7 +125,7 @@ export namespace DOM {
return this.document.createElementNS(namespace, tag);
}

setAttribute(element: Element, name: string, value: string, namespace?: Option<string>) {
setAttribute(element: Element, name: string, value: string, namespace: Option<string> = null) {
if (namespace) {
element.setAttributeNS(namespace, name, value);
} else {
Expand Down
13 changes: 0 additions & 13 deletions packages/@glimmer/runtime/lib/dom/normalize.ts
Expand Up @@ -31,19 +31,6 @@ export function normalizeTrustedValue(value: Opaque): TrustingInsertion {
return String(value);
}

export function normalizeValue(value: Opaque): CautiousInsertion {
if (isEmpty(value)) {
return '';
}
if (isString(value)) {
return value;
}
if (isSafeString(value) || isNode(value)) {
return value;
}
return String(value);
}

export function isEmpty(value: Opaque): boolean {
return value === null || value === undefined || typeof value.toString !== 'function';
}
Expand Down
6 changes: 1 addition & 5 deletions packages/@glimmer/runtime/lib/environment.ts
Expand Up @@ -8,10 +8,6 @@ import { DOMChanges, DOMTreeConstruction } from './dom/helper';
import { Reference, OpaqueIterable } from '@glimmer/reference';
import { UNDEFINED_REFERENCE, ConditionalReference } from './references';
import { DynamicAttributeFactory, defaultDynamicAttributes } from './vm/attributes/dynamic';
// import {
// defaultManagers,
// AttributeManager
// } from './dom/attribute-managers';

import {
PartialDefinition
Expand Down Expand Up @@ -456,7 +452,7 @@ export abstract class Environment {
transaction.commit();
}

attributeFor(element: Simple.Element, attr: string, isTrusting: boolean, namespace: Option<string>): DynamicAttributeFactory {
attributeFor(element: Simple.Element, attr: string, isTrusting: boolean, namespace: Option<string> = null): DynamicAttributeFactory {
return defaultDynamicAttributes(element, attr);
}

Expand Down
19 changes: 6 additions & 13 deletions packages/@glimmer/runtime/lib/vm/attributes/dynamic.ts
Expand Up @@ -5,6 +5,7 @@ import { sanitizeAttributeValue, requiresSanitization } from '../../dom/sanitize
import { normalizeProperty } from '../../dom/props';
import { SVG_NAMESPACE } from '../../dom/helper';
import { Attribute, AttributeOperation } from './index';
import { normalizeStringValue } from "@glimmer/runtime/lib/dom/normalize";

export interface DynamicAttributeFactory {
new(attribute: Attribute): DynamicAttribute;
Expand Down Expand Up @@ -59,7 +60,7 @@ export abstract class DynamicAttribute implements AttributeOperation {

export class SimpleDynamicAttribute extends DynamicAttribute {
set(dom: ElementBuilder, value: Opaque): void {
let normalizedValue = normalizeStringValue(value);
let normalizedValue = normalizeValue(value);

if (normalizedValue !== null) {
let { name, namespace } = this.attribute;
Expand All @@ -68,7 +69,7 @@ export class SimpleDynamicAttribute extends DynamicAttribute {
}

update(value: Opaque): void {
let normalizedValue = normalizeStringValue(value);
let normalizedValue = normalizeValue(value);
let { element, name } = this.attribute;

if (normalizedValue === null) {
Expand Down Expand Up @@ -126,13 +127,13 @@ export class SafeDynamicProperty extends DefaultDynamicProperty {

export class InputValueDynamicAttribute extends DefaultDynamicProperty {
set(dom: ElementBuilder, value: Opaque) {
dom.__setProperty('value', normalizeInputValue(value));
dom.__setProperty('value', normalizeStringValue(value));
}

update(value: Opaque) {
let input = <HTMLInputElement>this.attribute.element;
let currentValue = input.value;
let normalizedValue = normalizeInputValue(value);
let normalizedValue = normalizeStringValue(value);
if (currentValue !== normalizedValue) {
input.value = normalizedValue!;
}
Expand Down Expand Up @@ -165,15 +166,7 @@ function isUserInputValue(tagName: string, attribute: string) {
return (tagName === 'INPUT' || tagName === 'TEXTAREA') && attribute === 'value';
}

function normalizeInputValue(value: Opaque) {
if (value === null || value === undefined || typeof value.toString !== 'function') {
return '';
}

return `${value}`;
}

function normalizeStringValue(value: Opaque): Option<string> {
function normalizeValue(value: Opaque): Option<string> {
if (value === false || value === undefined || value === null || typeof value.toString === 'undefined') {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@glimmer/runtime/lib/vm/content/html.ts
Expand Up @@ -14,7 +14,7 @@ export default class DynamicHTMLContent extends DynamicContentBase {

if (value === lastValue) return this;

if (isSafeString(value) && isSafeString(lastValue) && value.toHTML() === lastValue.toHTML()) {
if (isSafeString(value) && value.toHTML() === lastValue.toHTML()) {
this.lastValue = value;
return this;
}
Expand All @@ -31,7 +31,7 @@ export class DynamicTrustedHTMLContent extends DynamicContentBase {
update(env: Environment, value: Opaque): DynamicContent {
let { lastValue } = this;

if (typeof value === 'string' && value === lastValue) return this;
if (value === lastValue) return this;
let newValue = normalizeTrustedValue(value);
if (newValue === lastValue) return this;

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Expand Up @@ -16,7 +16,7 @@
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
// "noUnusedParameters": true,
"noUnusedParameters": true,
"allowUnreachableCode": false,
"strictNullChecks": true,
"noImplicitReturns": true,
Expand Down

0 comments on commit b58d4d7

Please sign in to comment.