OpenEnergyTools / scl-lib

5 stars 4 forks source link

Document how to incorporate in a plugin #34

Open danyill opened 1 year ago

danyill commented 1 year ago

It's not altogether obvious how to incorporate this in a plugin, partly because we use import.meta.url to fetch the nsd JSON file. If this is not handled correctly, it causes a load error.

So in an open-scd-core plugin which uses this library, it is important that these statement are correctly translated so that the paths are correct.

If using rollup, the plugin, "Import Meta Assets" does this very easily and is likely useful for other reasons as well.

https://modern-web.dev/docs/building/rollup-plugin-import-meta-assets/

I've incorporated this into my oscd-subscriber-later-binding plugin in the following commit: https://github.com/danyill/oscd-subscriber-later-binding/commit/f101019220603e72dd2249116ddfec786727585a

We should document what is required for new users of this library.

trusz commented 1 year ago

I feel like a library like this should not really load files itself. I assume we talk about this spot: https://github.com/OpenEnergyTools/scl-lib/blob/012fdc1901e1b128e4a3b5dd9c1a9e9a6b1cfec2/tExtRef/extRefTypeRestrictions.ts#L2

The client should be able to decide when and how it loads these files.

danyill commented 1 year ago

The client should be able to decide when and how it loads these files.

Shouldn't the client just use the functions? If a file is required to use this library, I'd normally be happy to bundle it into my dependencies and tree-shake it as required... ⁉️

trusz commented 1 year ago

The problem is that you are making assumptions of the client's capabilities. Usually it falls to the client to orchestrate its libraries. Which one does what, and when. I usually do not like if libraries do something without me knowing it or having the ability to control it.

I think libraries should be configured and framework should work with conventions.

I would do something along these lines:

const nsd1 = await fetch(nsd1URL)
const nsd2 = await loadFromDB(nsd2URL)
const scl = new SCL(document, [nsd1,nsd2])