I’m new to Observable in general (never used the hosted version) but super excited about the new self-hosted Framework.
I am following the documentation and reading in the Javascript Imports section about moving code to components.
I had an inline JS block that had a function like:
const myFunction = (data, {width} = {}) {
return Plot.plot(/* function stuff */)
}
And further down in my Markdown file I had:
<div class="card">${resize((width) => myFunction(data, {width})}</div>
This worked just fine inline and displayed my chart with the data as expected.
Then I created a file called myFunction.js
and put it in the docs/components
folder as was suggested in the Routing docs. The file looks like this:
export const myFunction = (data, {width} = {}) {
return Plot.plot(/* function stuff */)
}
Then in my Markdown file, I have this in a JS block instead of the inline declaration of myFunction
.
import { myFunction } from './components/myFunction.js';
So far so good… The dev preview isn’t throwing any errors in the console or on the page.
However, my chart doesn’t show up now, and I can’t quite figure out what I’m doing wrong?
One thing I thought of was maybe I needed to import Plot
in my component file since it’s not in the Markdown anymore, but that throws an error when I do it, complaining that it’s not a local import so that’s not it?
Suggestions/help welcome!