Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamline resource creation api #798

Closed
Polleps opened this issue Jan 10, 2024 · 3 comments · Fixed by #804
Closed

Streamline resource creation api #798

Polleps opened this issue Jan 10, 2024 · 3 comments · Fixed by #804
Assignees
Labels

Comments

@Polleps
Copy link
Member

Polleps commented Jan 10, 2024

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

@Polleps Polleps added browser lib js @tomic/lib labels Jan 10, 2024
@joepio
Copy link
Member

joepio commented Jan 10, 2024

Some additional thoughts:

  • The parent is always required
  • A class is not required, but often useful
  • A subject could be generated, so it could be an optional argument.

@Polleps
Copy link
Member Author

Polleps commented Jan 10, 2024

I just realised we need store to set the parent and a class so going the store.newResource() route makes more sense

@joepio
Copy link
Member

joepio commented Jan 10, 2024

That way even the parent becomes optional - we could default to the serverURL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants