Skip to content

Commit

Permalink
using @ungap/template-tag-arguments instead of @ungap/template-literal
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Giammarchi committed Jan 11, 2019
1 parent babbca7 commit 4cf0bfe
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 107 deletions.
4 changes: 2 additions & 2 deletions cjs/hyper/render.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';
const WeakMap = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('@ungap/weakmap'));
const tta = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('@ungap/template-tag-arguments'));

const {OWNER_SVG_ELEMENT} = require('../shared/constants.js');
const {Tagger} = require('../objects/Updates.js');
const {reArguments} = require('../shared/utils.js');

// a weak collection of contexts that
// are already known to hyperHTML
Expand All @@ -15,7 +15,7 @@ const bewitched = new WeakMap;
// The `this` context is either a regular DOM node or a fragment.
function render() {
const wicked = bewitched.get(this);
const args = reArguments.apply(null, arguments);
const args = tta.apply(null, arguments);
if (wicked && wicked.template === args[0]) {
wicked.tagger.apply(null, args);
} else {
Expand Down
4 changes: 2 additions & 2 deletions cjs/hyper/wire.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';
const WeakMap = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('@ungap/weakmap'));
const tta = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('@ungap/template-tag-arguments'));

const Wire = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('hyperhtml-wire'));

const {Tagger} = require('../objects/Updates.js');
const {reArguments} = require('../shared/utils.js');

// all wires used per each context
const wires = new WeakMap;
Expand All @@ -31,7 +31,7 @@ const wire = (obj, type) => obj == null ?
const content = type => {
let wire, tagger, template;
return function () {
const args = reArguments.apply(null, arguments);
const args = tta.apply(null, arguments);
if (template !== args[0]) {
template = args[0];
tagger = new Tagger(type);
Expand Down
7 changes: 6 additions & 1 deletion cjs/objects/Updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const {
const Component = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('../classes/Component.js'));
const Wire = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('hyperhtml-wire'));
const Intent = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('./Intent.js'));
const { slice, text } = require('../shared/utils.js');

const observe = disconnected({Event: CustomEvent, WeakSet});

Expand Down Expand Up @@ -70,6 +69,12 @@ const isPromise_ish = value => value != null && 'then' in value;
// list of attributes that should not be directly assigned
const readOnly = /^(?:form|list)$/i;

// reused every slice time
const slice = [].slice;

// simplifies text node creation
const text = (node, text) => node.ownerDocument.createTextNode(text);

function Tagger(type) {
this.type = type;
return domtagger(this);
Expand Down
19 changes: 0 additions & 19 deletions cjs/shared/utils.js
Original file line number Diff line number Diff line change
@@ -1,20 +1 @@
'use strict';
const unique = (m => m.__esModule ? /* istanbul ignore next */ m.default : /* istanbul ignore next */ m)(require('@ungap/template-literal'));

// these are tiny helpers to simplify most common operations needed here
const text = (node, text) => node.ownerDocument.createTextNode(text);
exports.text = text;

// normalizes the template once for all arguments cases
const reArguments = function (template) {
const args = [unique(template)];
for (let i = 1, length = arguments.length; i < length; i++)
args[i] = arguments[i];
return args;
}
exports.reArguments = reArguments

// just recycling a one-off array to use slice
// in every needed place
const slice = [].slice;
exports.slice = slice;
7 changes: 4 additions & 3 deletions esm.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions esm/hyper/render.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import WeakMap from '@ungap/weakmap';
import tta from '@ungap/template-tag-arguments';

import {OWNER_SVG_ELEMENT} from '../shared/constants.js';
import {Tagger} from '../objects/Updates.js';
import {reArguments} from '../shared/utils.js';

// a weak collection of contexts that
// are already known to hyperHTML
Expand All @@ -14,7 +14,7 @@ const bewitched = new WeakMap;
// The `this` context is either a regular DOM node or a fragment.
function render() {
const wicked = bewitched.get(this);
const args = reArguments.apply(null, arguments);
const args = tta.apply(null, arguments);
if (wicked && wicked.template === args[0]) {
wicked.tagger.apply(null, args);
} else {
Expand Down
4 changes: 2 additions & 2 deletions esm/hyper/wire.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import WeakMap from '@ungap/weakmap';
import tta from '@ungap/template-tag-arguments';

import Wire from 'hyperhtml-wire';

import {Tagger} from '../objects/Updates.js';
import {reArguments} from '../shared/utils.js';

// all wires used per each context
const wires = new WeakMap;
Expand All @@ -30,7 +30,7 @@ const wire = (obj, type) => obj == null ?
const content = type => {
let wire, tagger, template;
return function () {
const args = reArguments.apply(null, arguments);
const args = tta.apply(null, arguments);
if (template !== args[0]) {
template = args[0];
tagger = new Tagger(type);
Expand Down
7 changes: 6 additions & 1 deletion esm/objects/Updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
import Component from '../classes/Component.js';
import Wire from 'hyperhtml-wire';
import Intent from './Intent.js';
import { slice, text } from '../shared/utils.js';

const observe = disconnected({Event: CustomEvent, WeakSet});

Expand Down Expand Up @@ -70,6 +69,12 @@ const isPromise_ish = value => value != null && 'then' in value;
// list of attributes that should not be directly assigned
const readOnly = /^(?:form|list)$/i;

// reused every slice time
const slice = [].slice;

// simplifies text node creation
const text = (node, text) => node.ownerDocument.createTextNode(text);

function Tagger(type) {
this.type = type;
return domtagger(this);
Expand Down
16 changes: 0 additions & 16 deletions esm/shared/utils.js

This file was deleted.

108 changes: 57 additions & 51 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1322,53 +1322,6 @@ var hyperHTML = (function (document) {
}
}([].slice);

var templateLiteral = function () {

var RAW = 'raw';
var isNoOp = false;

var _templateLiteral = function templateLiteral(tl) {
if ( // for badly transpiled literals
!(RAW in tl) || // for some version of TypeScript
tl.propertyIsEnumerable(RAW) || // and some other version of TypeScript
!Object.isFrozen(tl.raw) || // or for Firefox < 55
/Firefox\/(\d+)/.test((document.defaultView.navigator || {}).userAgent) && parseFloat(RegExp.$1) < 55) {
var forever = {};

_templateLiteral = function templateLiteral(tl) {
var key = RAW + tl.join(RAW);
return forever[key] || (forever[key] = tl);
};

return _templateLiteral(tl);
} else {
isNoOp = true;
return tl;
}
};

return function (tl) {
return isNoOp ? tl : _templateLiteral(tl);
};
}();

var text = function text(node, _text) {
return node.ownerDocument.createTextNode(_text);
}; // normalizes the template once for all arguments cases

var reArguments = function reArguments(template) {
var args = [templateLiteral(template)];

for (var i = 1, length = arguments.length; i < length; i++) {
args[i] = arguments[i];
}

return args;
}; // just recycling a one-off array to use slice
// in every needed place

var slice = [].slice;

var observe = disconnected({
Event: CustomEvent$1,
WeakSet: WeakSet$1
Expand Down Expand Up @@ -1419,7 +1372,13 @@ var hyperHTML = (function (document) {
}; // list of attributes that should not be directly assigned


var readOnly = /^(?:form|list)$/i;
var readOnly = /^(?:form|list)$/i; // reused every slice time

var slice = [].slice; // simplifies text node creation

var text = function text(node, _text) {
return node.ownerDocument.createTextNode(_text);
};

function Tagger(type) {
this.type = type;
Expand Down Expand Up @@ -1625,7 +1584,7 @@ var hyperHTML = (function (document) {
// it's pointless to transform or analyze anything
// different from text there but it's worth checking
// for possible defined intents.
text: function text$$1(node) {
text: function text(node) {
var oldValue;

var textContent = function textContent(value) {
Expand Down Expand Up @@ -1662,6 +1621,53 @@ var hyperHTML = (function (document) {
}
};

/*! (c) Andrea Giammarchi - ISC */
var templateLiteral = function () {

var RAW = 'raw';
var isNoOp = false;

var _templateLiteral = function templateLiteral(tl) {
if ( // for badly transpiled literals
!(RAW in tl) || // for some version of TypeScript
tl.propertyIsEnumerable(RAW) || // and some other version of TypeScript
!Object.isFrozen(tl[RAW]) || // or for Firefox < 55
/Firefox\/(\d+)/.test((document.defaultView.navigator || {}).userAgent) && parseFloat(RegExp.$1) < 55) {
var forever = {};

_templateLiteral = function templateLiteral(tl) {
for (var key = '.', i = 0; i < tl.length; i++) {
key += tl[i].length + '.' + tl[i];
}

return forever[key] || (forever[key] = tl);
};
} else {
isNoOp = true;
}

return TL(tl);
};

return TL;

function TL(tl) {
return isNoOp ? tl : _templateLiteral(tl);
}
}();

function tta (template) {
var length = arguments.length;
var args = [templateLiteral(template)];
var i = 1;

while (i < length) {
args.push(arguments[i++]);
}

return args;
}

var wires = new WeakMap$1(); // A wire is a callback used as tag function
// to lazily relate a generic object to a template literal.
// hyper.wire(user)`<div id=user>${user.name}</div>`; => the div#user
Expand All @@ -1685,7 +1691,7 @@ var hyperHTML = (function (document) {
var content = function content(type) {
var wire, tagger, template;
return function () {
var args = reArguments.apply(null, arguments);
var args = tta.apply(null, arguments);

if (template !== args[0]) {
template = args[0];
Expand Down Expand Up @@ -1743,7 +1749,7 @@ var hyperHTML = (function (document) {

function render() {
var wicked = bewitched.get(this);
var args = reArguments.apply(null, arguments);
var args = tta.apply(null, arguments);

if (wicked && wicked.template === args[0]) {
wicked.tagger.apply(null, args);
Expand Down
Loading

0 comments on commit 4cf0bfe

Please sign in to comment.