Closed
Description
Creating new resources with @tomic/lib is currently very unintuitive, to create a resource you need to "fetch" or "get" a resource but tell the store it is new. It also doesn't set any properties so you can't directly save it.
We should have a separate function to create new resources e.g. store.newResource()
. Ideally this also takes a class(es) and parent because you have to set those on all resources anyway.
Something like
const resource = store.newResource('https://my-folder', dataBrowser.classes.folder, 'https://my-parent');
Alternatively we could add an overload to the Resource
constructor e.g.
const resource = new Resource('https://my-folder', dataBrowser.classes.folder, 'https://my-parent');
Maybe we can add a way to quickly set additional properties too
Activity
joepio commentedon Jan 10, 2024
Some additional thoughts:
Polleps commentedon Jan 10, 2024
I just realised we need store to set the parent and a class so going the
store.newResource()
route makes more sensejoepio commentedon Jan 10, 2024
That way even the parent becomes optional - we could default to the
serverURL
.#798 Streamline Resource Creation API
#798 Changed docs to use store.newResource
#798 Streamline Resource Creation API
#798 Changed docs to use store.newResource