Skip to content

Commit

Permalink
chore: update code styling for new eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban committed Nov 11, 2019
1 parent 3f0e1f7 commit cd7d76e
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/children.js
Expand Up @@ -15,7 +15,7 @@ function walk(node, fn, options, items = []) {
}

export default function children(hybridsOrFn, options = { deep: false, nested: false }) {
const fn = typeof hybridsOrFn === 'function' ? hybridsOrFn : hybrids => hybrids === hybridsOrFn;
const fn = typeof hybridsOrFn === 'function' ? hybridsOrFn : (hybrids) => hybrids === hybridsOrFn;
return {
get(host) { return walk(host, fn, options); },
connect(host, key, invalidate) {
Expand Down
6 changes: 3 additions & 3 deletions src/define.js
Expand Up @@ -44,7 +44,7 @@ function compile(Hybrid, descriptors) {
});

if (config.connect) {
Hybrid.callbacks.push(host => config.connect(host, key, () => {
Hybrid.callbacks.push((host) => config.connect(host, key, () => {
cache.invalidate(host, key);
}));
}
Expand All @@ -71,11 +71,11 @@ if (process.env.NODE_ENV !== 'production') {
fn(node);

Array.from(node.children)
.forEach(el => walkInShadow(el, fn));
.forEach((el) => walkInShadow(el, fn));

if (node.shadowRoot) {
Array.from(node.shadowRoot.children)
.forEach(el => walkInShadow(el, fn));
.forEach((el) => walkInShadow(el, fn));
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/emitter.js
Expand Up @@ -10,7 +10,7 @@ function getListeners(target) {
}

const queue = new Set();
const run = fn => fn();
const run = (fn) => fn();

function execute() {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/parent.js
Expand Up @@ -16,9 +16,9 @@ function walk(node, fn) {
}

export default function parent(hybridsOrFn) {
const fn = typeof hybridsOrFn === 'function' ? hybridsOrFn : hybrids => hybrids === hybridsOrFn;
const fn = typeof hybridsOrFn === 'function' ? hybridsOrFn : (hybrids) => hybrids === hybridsOrFn;
return {
get: host => walk(host, fn),
get: (host) => walk(host, fn),
connect(host, key, invalidate) {
const target = host[key];
if (target) {
Expand Down
2 changes: 1 addition & 1 deletion src/property.js
@@ -1,6 +1,6 @@
import { camelToDash } from './utils';

const defaultTransform = v => v;
const defaultTransform = (v) => v;

const objectTransform = (value) => {
if (typeof value !== 'object') {
Expand Down
4 changes: 2 additions & 2 deletions src/template/core.js
Expand Up @@ -74,7 +74,7 @@ function createSignature(parts, styles) {
if (IS_IE) {
return signature.replace(
/style\s*=\s*(["][^"]+["]|['][^']+[']|[^\s"'<>/]+)/g,
match => `${ATTR_PREFIX}${match}`,
(match) => `${ATTR_PREFIX}${match}`,
);
}

Expand Down Expand Up @@ -150,7 +150,7 @@ export function compileTemplate(rawParts, isSVG, styles) {
if (isSVG) {
const svgRoot = template.content.firstChild;
template.content.removeChild(svgRoot);
Array.from(svgRoot.childNodes).forEach(node => template.content.appendChild(node));
Array.from(svgRoot.childNodes).forEach((node) => template.content.appendChild(node));
}

replaceComments(template.content);
Expand Down
2 changes: 1 addition & 1 deletion src/template/resolvers/array.js
Expand Up @@ -37,7 +37,7 @@ export default function resolveArray(host, target, value) {

if (lastEntries) {
const ids = new Set();
entries.forEach(entry => ids.add(entry.id));
entries.forEach((entry) => ids.add(entry.id));

lastEntries = lastEntries.filter((entry) => {
if (!ids.has(entry.id)) {
Expand Down
4 changes: 2 additions & 2 deletions src/template/resolvers/class.js
@@ -1,8 +1,8 @@
function normalizeValue(value, set = new Set()) {
if (Array.isArray(value)) {
value.forEach(className => set.add(className));
value.forEach((className) => set.add(className));
} else if (value !== null && typeof value === 'object') {
Object.keys(value).forEach(key => value[key] && set.add(key));
Object.keys(value).forEach((key) => value[key] && set.add(key));
} else {
set.add(value);
}
Expand Down
2 changes: 1 addition & 1 deletion test/helpers.js
Expand Up @@ -2,7 +2,7 @@ export function test(html) {
const template = document.createElement('template');
template.innerHTML = html;

return spec => (done) => {
return (spec) => (done) => {
const wrapper = document.createElement('div');
document.body.appendChild(wrapper);
wrapper.appendChild(template.content.cloneNode(true));
Expand Down
2 changes: 1 addition & 1 deletion test/runner.js
Expand Up @@ -2,4 +2,4 @@
window.env = 'development';

const req = require.context('./spec/', true, /\.js$/);
req.keys().forEach(key => req(key));
req.keys().forEach((key) => req(key));
10 changes: 5 additions & 5 deletions test/spec/children.js
Expand Up @@ -72,7 +72,7 @@ describe('children:', () => {
});
}));

it('updates parent computed property', tree(el => resolveTimeout(() => {
it('updates parent computed property', tree((el) => resolveTimeout(() => {
expect(el.customName).toBe('one');
el.children[0].customName = 'four';

Expand All @@ -84,7 +84,7 @@ describe('children:', () => {

describe('function condition', () => {
define('test-children-fn', {
direct: children(hybrids => hybrids === child),
direct: children((hybrids) => hybrids === child),
});

const tree = test(`
Expand Down Expand Up @@ -135,7 +135,7 @@ describe('children:', () => {
});
}));

it('does not update if other children element is invalidated', tree(el => resolveRaf(() => {
it('does not update if other children element is invalidated', tree((el) => resolveRaf(() => {
el.children[0].children[0].customName = 'test';
return resolveRaf(() => {
expect(el.deep).toEqual([
Expand Down Expand Up @@ -206,7 +206,7 @@ describe('children:', () => {
render: ({ items }) => html`
<test-dynamic-parent>
<test-dynamic-child name="one"></test-dynamic-child>
${items.map(name => html`
${items.map((name) => html`
<test-dynamic-child name="${name}"></test-dynamic-child>
`.key(name))}
</test-dynamic-parent>
Expand All @@ -217,7 +217,7 @@ describe('children:', () => {
<test-dynamic-wrapper></test-dynamic-wrapper>
`);

it('adds dynamic item', tree(el => resolveTimeout(() => {
it('adds dynamic item', tree((el) => resolveTimeout(() => {
el.items = ['two'];
return resolveTimeout(() => {
expect(el.shadowRoot.children[0].shadowRoot.children[0].children.length).toBe(2);
Expand Down
58 changes: 29 additions & 29 deletions test/spec/html.js
Expand Up @@ -17,8 +17,8 @@ describe('html:', () => {
document.body.removeChild(fragment);
});

const getArrayValues = f => Array.from(f.children)
.map(child => child.textContent);
const getArrayValues = (f) => Array.from(f.children)
.map((child) => child.textContent);

it('renders static content', () => {
const render = html`<div>static content<!-- some comment --></div>`;
Expand All @@ -28,7 +28,7 @@ describe('html:', () => {

it('creates template unique id', () => {
const renderOne = () => html`<div>value:</div>`;
const renderTwo = value => html`<div>value:${value}</div>`;
const renderTwo = (value) => html`<div>value:${value}</div>`;

renderOne()({}, fragment);
renderTwo(0)({}, fragment);
Expand All @@ -37,7 +37,7 @@ describe('html:', () => {
});

it('reuses the same elements when re-render', () => {
const render = value => html`<!-- some comment --><div>${value}</div>`;
const render = (value) => html`<!-- some comment --><div>${value}</div>`;
render(0)(fragment);
const div = fragment.children[0];
render(1)(fragment);
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('html:', () => {
render: renderFactory(() => html`content`, { shadowRoot: false }),
});

const render = flag => html`${flag && html`<test-replace-trigger></test-replace-trigger>`}<button></button>`;
const render = (flag) => html`${flag && html`<test-replace-trigger></test-replace-trigger>`}<button></button>`;
render(true)(fragment);

resolveTimeout(() => {
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('html:', () => {
});

describe('attribute expression with non existing property', () => {
const render = value => html`<div text-property="${value}"></div>`;
const render = (value) => html`<div text-property="${value}"></div>`;

beforeEach(() => render('value')(fragment));

Expand Down Expand Up @@ -156,8 +156,8 @@ describe('html:', () => {
});

describe('class expression attribute', () => {
const render = classList => html`<div class=${classList}></div>`;
const hasClass = className => fragment.children[0].classList.contains(className);
const render = (classList) => html`<div class=${classList}></div>`;
const hasClass = (className) => fragment.children[0].classList.contains(className);

it('sets string value', () => {
render('class-one')(fragment);
Expand Down Expand Up @@ -194,8 +194,8 @@ describe('html:', () => {
});

describe('style expression attribute', () => {
const renderObject = styleList => html`<div style="${styleList}"></div>`;
const renderAttr = text => html`
const renderObject = (styleList) => html`<div style="${styleList}"></div>`;
const renderAttr = (text) => html`
<div style = "color: red; ${text}" asd="<>/">
<div style="color: red; ${text}"></div>
</div>
Expand Down Expand Up @@ -239,8 +239,8 @@ describe('html:', () => {
});

describe('event attribute expression', () => {
const render = value => html`<button onclick=${value}></button>`;
const renderWithQuotes = value => html`<button onclick="${value}"></button>`;
const render = (value) => html`<button onclick=${value}></button>`;
const renderWithQuotes = (value) => html`<button onclick="${value}"></button>`;

const click = () => fragment.children[0].click();
let spy;
Expand Down Expand Up @@ -337,7 +337,7 @@ describe('html:', () => {
});

describe('template content expression', () => {
const render = flag => html`
const render = (flag) => html`
<div>value: ${flag && html`<span>${'one'}</span>`}</div>
`;

Expand All @@ -354,7 +354,7 @@ describe('html:', () => {
});

describe('flat array content expression with primitive values', () => {
const render = items => html`${items}`;
const render = (items) => html`${items}`;

beforeEach(() => { render([1, 2, 3])(fragment); });

Expand All @@ -379,7 +379,7 @@ describe('html:', () => {
});

describe('flat array content expression', () => {
const render = items => html` ${items && items.map(v => html` <span>${v}</span> `.key(v))} `;
const render = (items) => html` ${items && items.map((v) => html` <span>${v}</span> `.key(v))} `;

beforeEach(() => {
render([1, 2, 3])(fragment);
Expand Down Expand Up @@ -445,9 +445,9 @@ describe('html:', () => {
});

describe('nested array content expression', () => {
const renderItem = item => html`<span>${item}</span>`.key(item);
const renderArray = array => html`${array.map(renderItem)}`.key(array.join(''));
const render = items => html`${items && items.map(renderArray)} static value`;
const renderItem = (item) => html`<span>${item}</span>`.key(item);
const renderArray = (array) => html`${array.map(renderItem)}`.key(array.join(''));
const render = (items) => html`${items && items.map(renderArray)} static value`;

beforeEach(() => {
render([[1, 2, 3], [4, 5, 6], [7]])(fragment);
Expand Down Expand Up @@ -490,7 +490,7 @@ describe('html:', () => {
});

describe('multiple nested array content expression', () => {
const render = array => html`${array.map((item) => {
const render = (array) => html`${array.map((item) => {
if (Array.isArray(item)) {
return render(item);
}
Expand Down Expand Up @@ -520,12 +520,12 @@ describe('html:', () => {
{ id: 1, children: [{ id: 3 }] },
{ id: 2 },
];
const renderData = item => html`
const renderData = (item) => html`
<span>${item.id}</span>
${item.children && item.children.map(renderData)}
`.key(item.id);

const renderWrapper = list => html`
const renderWrapper = (list) => html`
${list.map(renderData)}
`;

Expand All @@ -537,9 +537,9 @@ describe('html:', () => {

describe('table', () => {
it('should render table with rows', () => {
const renderRow = v => html`<tr><td>${v}</td></tr>`.key(v);
const renderRow = (v) => html`<tr><td>${v}</td></tr>`.key(v);
const renderTable = html`
<table><tbody>${[1, 2].map(v => renderRow(v))} ${[3, 4].map(v => renderRow(v))}</tbody></table>`;
<table><tbody>${[1, 2].map((v) => renderRow(v))} ${[3, 4].map((v) => renderRow(v))}</tbody></table>`;

renderTable({}, fragment);
expect(fragment.children[0].outerHTML)
Expand Down Expand Up @@ -635,7 +635,7 @@ describe('html:', () => {

it('shows placeholder after delay', (done) => {
render(
new Promise(resolve => setTimeout(resolve, 500)),
new Promise((resolve) => setTimeout(resolve, 500)),
'value',
html`<div>loading...</div>`,
)(fragment);
Expand Down Expand Up @@ -740,12 +740,12 @@ describe('html:', () => {
<test-shady-parent></test-shady-parent>
`);

it('should set custom property', shadyTree(el => resolveTimeout(() => {
it('should set custom property', shadyTree((el) => resolveTimeout(() => {
const { color } = window.getComputedStyle(el.shadowRoot.children[0].shadowRoot.children[0]);
expect(color).toBe('rgb(255, 0, 0)');
})));

it('should update custom property', shadyTree(el => resolveTimeout(() => {
it('should update custom property', shadyTree((el) => resolveTimeout(() => {
el.active = true;
return resolveTimeout(() => {
const { color } = window.getComputedStyle(el.shadowRoot.children[0].shadowRoot.children[0]);
Expand All @@ -755,7 +755,7 @@ describe('html:', () => {
});

describe('ShadyCSS encapsulation', () => {
const render = text => html`
const render = (text) => html`
<div>${text}</div>
<style>
div {
Expand Down Expand Up @@ -808,7 +808,7 @@ describe('html:', () => {
beforeEach(() => {
if (!shadyCSSApplied) {
window.ShadyCSS = {
prepareTemplate: template => template,
prepareTemplate: (template) => template,
styleElement: jasmine.createSpy(),
styleSubtree: jasmine.createSpy(),
};
Expand Down Expand Up @@ -857,7 +857,7 @@ describe('html:', () => {
}
}

const render = value => html`<test-external-element>${value}</test-external-element>`
const render = (value) => html`<test-external-element>${value}</test-external-element>`
.define({ TestExternalElement });

it('renders external element with slotted value', (done) => {
Expand Down
6 changes: 3 additions & 3 deletions test/spec/parent.js
Expand Up @@ -12,12 +12,12 @@ describe('parent:', () => {
define('test-parent-child', {
parent: parent(parentHybrids),
computed: {
get: host => `${host.parent.customProperty} other value`,
get: (host) => `${host.parent.customProperty} other value`,
},
});

define('test-parent-child-fn', {
parent: parent(hybrids => hybrids === parentHybrids),
parent: parent((hybrids) => hybrids === parentHybrids),
});

const directParentTree = test(`
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('parent:', () => {
expect(el.parent).toBe(null);
}));

it('updates child computed property', directParentTree(el => Promise.resolve().then(() => {
it('updates child computed property', directParentTree((el) => Promise.resolve().then(() => {
const child = el.children[0];

expect(el.customProperty).toBe('value');
Expand Down
2 changes: 1 addition & 1 deletion test/spec/property.js
Expand Up @@ -9,7 +9,7 @@ describe('property:', () => {
stringProp: property('value'),
numberProp: property(123),
boolProp: property(false),
funcProp: property(value => ({
funcProp: property((value) => ({
value,
})),
objProp: property(objProp),
Expand Down

0 comments on commit cd7d76e

Please sign in to comment.