0.4.0 • Published 5 years ago

@sealcode/cosealious v0.4.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

Cosealious

Helper for using REST APIs build with Sealious in the web, with React hooks

Usage

Describe a collection

First, you need to tell Coselaious what is the structure of the collections on the back-end.

import {CollectionItem, CollectionClient} from "@sealcode/cosealious";

const MyCollectionFields = {
	name: "",
	age: "",
	best_friend: "" // a reference to other collection
}


export class MyCollectionItem extends CollectionItem<typeof MyCollectionFields> {
	getInfo() {
		return {
			collection_name: "my-collection",
			fields: MyCollectionFields,
			writable_fields: Object.keys(MyCollectionFields) as Array<
				keyof typeof MyCollectionFields
			>,
			fields_with_attachments: ["best_friend"] as Array<
				keyof typeof MyCollectionFields
			>,
		};
	}
	
	// you can extend the collection item class with your own methods, if you like
}

export class MyCollectionClient extends CollectionClient<MyCollectionItem> {
	collection_name = "my-collection";
	item_constructor = MyCollectionItem;
}

Then you can use it in a component:

import {useCollection} from "@sealcode/cosealious";

function component(){
	const [myCollectionClient, items, client_params] = useCollection(
		MyCollectionClient,
		{
			filter: { when: getDate()  },
			sort: { when: "asc" },
		}
	);
	
	// ...
	
	return items.map(item => <div>entry.data.when</div>);
}
0.4.0

5 years ago

0.3.0

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.2.2

5 years ago

0.1.12

5 years ago

0.1.10

5 years ago

0.1.11

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.2

5 years ago

0.1.7

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago