From f0f5e5e6b882ce597c71f7cf5cd6624d3b79d813 Mon Sep 17 00:00:00 2001 From: MirrorBytes Date: Wed, 23 Dec 2020 10:49:33 -0500 Subject: [PATCH] fix: eslint error and rerender issue that wouldn't use props --- .eslintrc.js | 2 +- src/pure.js | 45 ++++++++++++++++++++++++++------------------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index a8bb5e0..4ef4d17 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -15,7 +15,7 @@ module.exports = { ], rules: { 'max-len': ['warn', { code: 100 }], - 'simple-import-sort/sort': 'error', + 'simple-import-sort/imports': 'error', 'no-multiple-empty-lines': ['error', { max: 2, maxBOF: 2, maxEOF: 0 }] }, overrides: [ diff --git a/src/pure.js b/src/pure.js index 8651539..cf04db8 100644 --- a/src/pure.js +++ b/src/pure.js @@ -15,28 +15,35 @@ const render = ( target = target || container.appendChild(document.createElement('div')) const ComponentConstructor = Component.default || Component - const isProps = !Object.keys(options).some(option => svleteComponentOptions.includes(option)) - - // Check if any props and Svelte options were accidentally mixed. - if (!isProps) { - const unrecognizedOptions = Object - .keys(options) - .filter(option => !svleteComponentOptions.includes(option)) - - if (unrecognizedOptions.length > 0) { - throw Error(` - Unknown options were found [${unrecognizedOptions}]. This might happen if you've mixed - passing in props with Svelte options into the render function. Valid Svelte options - are [${svleteComponentOptions}]. You can either change the prop names, or pass in your - props for that component via the \`props\` option.\n\n - Eg: const { /** Results **/ } = render(MyComponent, { props: { /** props here **/ } })\n\n - `) + + const checkProps = (options) => { + const isProps = !Object.keys(options).some(option => svleteComponentOptions.includes(option)) + + // Check if any props and Svelte options were accidentally mixed. + if (!isProps) { + const unrecognizedOptions = Object + .keys(options) + .filter(option => !svleteComponentOptions.includes(option)) + + if (unrecognizedOptions.length > 0) { + throw Error(` + Unknown options were found [${unrecognizedOptions}]. This might happen if you've mixed + passing in props with Svelte options into the render function. Valid Svelte options + are [${svleteComponentOptions}]. You can either change the prop names, or pass in your + props for that component via the \`props\` option.\n\n + Eg: const { /** Results **/ } = render(MyComponent, { props: { /** props here **/ } })\n\n + `) + } + + return options } + + return { props: options } } const component = new ComponentConstructor({ target, - ...(isProps ? { props: options } : options) + ...checkProps(options) }) containerCache.set(container, { target, component }) @@ -53,8 +60,8 @@ const render = ( // eslint-disable-next-line no-new const newComponent = new ComponentConstructor({ - ...options, - target + target, + ...checkProps(options) }) containerCache.set(container, { target, newComponent })