Skip to content

Commit

Permalink
Add tests for utils.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Klingler committed Jun 8, 2018
1 parent c55205b commit 6924cdd
Show file tree
Hide file tree
Showing 10 changed files with 5,824 additions and 74 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
coverage
2 changes: 1 addition & 1 deletion dist/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Object.defineProperty(exports, "__esModule", { value: true });
var utils_1 = require("./utils");
var removeServersideStyles = function (styleElementSelector) {
console.log('querying');
var previousStyleTarget = document.querySelector(styleElementSelector);
if (previousStyleTarget) {
previousStyleTarget.remove();
Expand All @@ -22,6 +21,7 @@ var makeDomUpdater = function (styleElementSelector) {
};
exports.makeModule = function (styleElementSelector) {
if (styleElementSelector === void 0) { styleElementSelector = undefined; }
// Serverside styles are only removed the first time updateDOM is called
var domUpdater = utils_1.alternateFirstInvocation(function () { return makeDomUpdater(styleElementSelector); }, function () { return makeDomUpdater(); });
var updateDOM = function (oldNode, newNode) { return domUpdater.next().value(oldNode, newNode); };
return {
Expand Down
14 changes: 6 additions & 8 deletions dist/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ exports.collectStyles = function (node) {
return instance.getStyles();
};
var traverseVNode = function (node, instance) {
if (utils_1.isVNode(node)) {
var data = node.data;
if (data.css) {
instance.style(data.css);
}
if (node.children) {
node.children.forEach(function (child) { return traverseVNode(child, instance); });
}
var data = node.data;
if (data.css) {
instance.style(data.css);
}
if (node.children) {
node.children.forEach(function (child) { return traverseVNode(child, instance); });
}
};
2 changes: 1 addition & 1 deletion dist/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VNode } from 'snabbdom/vnode';
export declare const isVNode: (vNode: string | VNode) => vNode is VNode;
export declare const makeClassName: (oldClassName: string, newClassName: string) => string;
export declare const updateVNode: (node: VNode, attributeAccessor: (attribute: string, className: string) => void) => void;
export declare function alternateFirstInvocation(first: () => any, subsequent: () => any): IterableIterator<any>;
9 changes: 3 additions & 6 deletions dist/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
};
Object.defineProperty(exports, "__esModule", { value: true });
var typestyle_1 = require("typestyle");
exports.isVNode = function (vNode) {
return vNode.length === undefined;
exports.makeClassName = function (oldClassName, newClassName) {
return (oldClassName + " " + newClassName).trim();
};
exports.updateVNode = function (node, attributeAccessor) {
var data = node.data;
if (data.css) {
data.props = data.props || {};
var styleClass = typestyle_1.style(data.css);
var oldClassName = data.props.className || '';
var newClassName = (oldClassName + " " + styleClass).trim();
attributeAccessor('class', newClassName);
attributeAccessor('class', exports.makeClassName(data.props.className || '', typestyle_1.style(data.css)));
}
};
function alternateFirstInvocation(first, subsequent) {
Expand Down
Loading

0 comments on commit 6924cdd

Please sign in to comment.