<!-- Source: https://docs.squirro.com/en/latest/technical/widgets/sdk/factories.html -->
# Factories

## ItemFactory

**`class ItemFactory()`**

A factory class for item collections

**`static ItemFactory.ItemFactoryOptions()`**

Arguments

- `url` (`string`) – Custom URL for collection
- `customParameters` (`object`) – Custom parameters object

**`static ItemFactory.create(dashboardState, project, options)`**

Creates the item collection

Arguments

- `dashboardState` (`Store`) – The dashboardState zustand store (this.options.dashboardState)
- `project` (`Model`) – The project (this.options.project)
- `options` (`ItemFactoryOptions`) – Additional options

Returns

**Collection** – - The items collection

**Examples:**

```js
var factory = Factories.Collections.Items;
var collection = factory.create(this.options.dashboardState, this.options.project, options);
```

**`static ItemFactory.createFromParams(params, url)`**

Creates the item collection from a parameters object

Arguments

- `params` (`Object`) – The parameters object
- `url` (`String`) – Custom url, if required

Returns

**Collection** – - The items collection

**Examples:**

```js
var factory = Factories.Collections.Items;
var collection = factory.createFromParams(this.getCollectionParams());
```

## AggregationsFactory

**`class AggregationsFactory()`**

A factory class for item collections

**`static AggregationsFactory.AggregationsFactoryOptions()`**

Arguments

- `dashboardState` (`Model`) – The dashboardState (this.options.dashboardState)
- `project` (`Model`) – The project (this.options.project)
- `content` (`String`) – If fetch is not overriden, specifies the outer aggregation field
- `limit` (`String`) – If fetch is not overriden, specifies size of the aggregation
- `field` (`String`) – If fetch is not overriden, specifies the inner aggregation field
- `aggregate_method` (`String`) – If fetch is not overriden, specifies aggregation method

**`static AggregationsFactory.create(type, options)`**

Creates the aggregations collection

Arguments

- `type` (`string`) – Collection type, used for caching so make it unique per widget
- `extensions` (`AggregationsFactoryOptions`) – Functions and properties in this object will be attached to the created collection prototype

Returns

**Collection** – - The aggregations collection

**Examples:**

```js
var factory = Factories.Collections.Aggregations;
var collection = factory.create('MyCollection', this.getCollectionParams());
```

**`static AggregationsFactory.createCommunities(type, project, dashboardState, limit, communityTypes, options)`**

Creates the community aggregations collection

Arguments

- `type` (`string`) – Collection type, used for caching so make it unique per widget
- `extensions` (`AggregationsFactoryOptions`) – Functions and properties in this object will be attached to the created collection prototype

Returns

**Collection** – - The aggregations collection

**Examples:**

```js
var factory = Factories.Collections.Aggregations;
var collection = factory.createCommunities('MyCollection', this.getCollectionParams());
```

**`static AggregationsFactory.createFacets(type, project, dashboardState, limit, fields, options)`**

Creates the facets aggregations collection

Arguments

- `type` (`string`) – Collection type, used for caching so make it unique per widget
- `extensions` (`AggregationsFactoryOptions`) – Functions and properties in this object will be attached to the created collection prototype

Returns

**Collection** – - The aggregations collection

**Examples:**

```js
var factory = Factories.Collections.Aggregations;
var collection = factory.createFacets('MyCollection', this.getCollectionParams());
```

## FacetsFactory

**`class FacetsFactory()`**

A factory class for item collections

**`static FacetsFactory.FacetsFactoryOptions()`**

Arguments

- `itemsCollection` (`Collection`) – If passed, links the collection to the item collection updates
- `nof_facets` ([`Number`](properties.md#Number)) – Limits the number of facet values per facet
- `facet_fields` (`Array.<string>`) – Only fetch specific facet fields
- `url` (`string`) – Custom URL passed from custom widgets
- `customParameters` (`object`) – Custom parameters object

**`static FacetsFactory.create(dashboardState, project, options)`**

Creates the facets collection

Arguments

- `dashboardState` (`Store`) – The dashboardState zustand store (this.options.dashboardState)
- `project` (`Model`) – The project (this.options.project)
- `options` (`FacetsFactoryOptions`) – Options

Returns

**Collection** – - The items collection

**Examples:**

```js
var factory = Factories.Collections.Facets;
var collection = factory.create(this.options.dashboardState, this.options.project);
```

## MockItemFactory

**`class MockItemFactory()`**

A factory class for mocked item collections

**`static MockItemFactory.create(dashboardState, project, items=null)`**

Creates the mocked item collection, with preloaded data and detached from the backend

Arguments

- `dashboardState` (`Store`) – The dashboardState zustand store (this.options.dashboardState)
- `project` (`Model`) – The project (this.options.project)
- `items` (`Array.<object>`) – Items to preload the collection with

Returns

**Collection** – - The items collection

**Examples:**

```js
var factory = Factories.Collections.MockItems;
var collection = factory.create(this.options.dashboardState, this.options.project, [{ title: 'Item title' }]);
```
