---
title: "ReverseModel"
---
Defined in: [api/node/typescript/models.ts:674](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L674)

ReverseModel acts as an adapter model for a given source model by reversing
all its rows. This means that the first row in the source model is the last
row of this model, the second row is the second last, and so on.

### Example

```js
const source = new ArrayModel([1, 2, 3, 4, 5]);
const reversed = new ReverseModel(source);

// prints 5, 4, 3, 2, 1
for (const x of reversed) {
    console.log(x);
}
```

## Extends

- `NativeAdapterModel`\<`T`\>

## Type Parameters

### T

`T`

## Constructors

### Constructor

> **new ReverseModel**\<`T`\>(`sourceModel`): `ReverseModel`\<`T`\>

Defined in: [api/node/typescript/models.ts:685](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L685)

Constructs a new ReverseModel that provides a reversed view on the given
`sourceModel`.

#### Parameters

##### sourceModel

[`Model`](/latest/docs/node/api/classes/model/)\<`T`\>

the wrapped model.

#### Returns

`ReverseModel`\<`T`\>

#### Overrides

`NativeAdapterModel<T>.constructor`

## Properties

### sourceModel

> `readonly` **sourceModel**: [`Model`](/latest/docs/node/api/classes/model/)\<`T`\>

Defined in: [api/node/typescript/models.ts:678](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L678)

The source model that this ReverseModel reverses rows from.

## Accessors

### \[nativeModelKey\]

#### Get Signature

> **get** **\[nativeModelKey\]**(): `NativeModel` \| `undefined`

Defined in: [api/node/typescript/models.ts:424](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L424)

##### Returns

`NativeModel` \| `undefined`

#### Inherited from

`NativeAdapterModel.[nativeModelKey]`

## Methods

### \[iterator\]()

> **\[iterator\]**(): `Iterator`\<`T`\>

Defined in: [api/node/typescript/models.ts:195](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L195)

#### Returns

`Iterator`\<`T`\>

#### Inherited from

`NativeAdapterModel.[iterator]`

***

### filter()

> **filter**(`filterFunction`): [`FilterModel`](/latest/docs/node/api/classes/filtermodel/)\<`T`\>

Defined in: [api/node/typescript/models.ts:118](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L118)

Returns a new Model that only contains the rows of this model for which
`filterFunction` returns true.

#### Parameters

##### filterFunction

(`data`) => `boolean`

returns true if a row should be visible.

#### Returns

[`FilterModel`](/latest/docs/node/api/classes/filtermodel/)\<`T`\>

a new [FilterModel](/latest/docs/node/api/classes/filtermodel/) that wraps the current model.

#### Inherited from

`NativeAdapterModel.filter`

***

### insertRow()

> **insertRow**(`_index`, `_data`): `void`

Defined in: [api/node/typescript/models.ts:191](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L191)

Implementations of this function must add a row at the specified index, pushing all next
rows to the right.
Throws when the model rejects the modification; the default implementation
always throws.

#### Parameters

##### \_index

`number`

index of the row to insert.

##### \_data

`T`

new data item to store in a new row.

#### Returns

`void`

#### Inherited from

`NativeAdapterModel.insertRow`

***

### map()

> **map**\<`U`\>(`mapFunction`): [`MapModel`](/latest/docs/node/api/classes/mapmodel/)\<`T`, `U`\>

Defined in: [api/node/typescript/models.ts:108](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L108)

Returns a new Model where all elements are mapped by the function `mapFunction`.

#### Type Parameters

##### U

`U`

#### Parameters

##### mapFunction

(`data`) => `U`

maps the data from T to U.

#### Returns

[`MapModel`](/latest/docs/node/api/classes/mapmodel/)\<`T`, `U`\>

a new [MapModel](/latest/docs/node/api/classes/mapmodel/) that wraps the current model.

#### Inherited from

`NativeAdapterModel.map`

***

### pushRow()

> **pushRow**(`data`): `void`

Defined in: [api/node/typescript/models.ts:169](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L169)

Adds a line to the model with the provided data.
Throws when the model rejects the modification.
The default implementation calls [Model.insertRow](/latest/docs/node/api/classes/model/#insertrow) with the row count.

#### Parameters

##### data

`T`

new data item to store in a new row.

#### Returns

`void`

#### Inherited from

`NativeAdapterModel.pushRow`

***

### removeRow()

> **removeRow**(`_index`): `void`

Defined in: [api/node/typescript/models.ts:179](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L179)

Implementations of this function must remove the row at the specified index.
Throws when the model rejects the modification; the default implementation
always throws.

#### Parameters

##### \_index

`number`

index of the row to remove.

#### Returns

`void`

#### Inherited from

`NativeAdapterModel.removeRow`

***

### reverse()

> **reverse**(): `ReverseModel`\<`T`\>

Defined in: [api/node/typescript/models.ts:137](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L137)

Returns a new Model with the same rows as this model, in reverse order.

#### Returns

`ReverseModel`\<`T`\>

a new [ReverseModel](/latest/docs/node/api/classes/reversemodel/) that wraps the current model.

#### Inherited from

`NativeAdapterModel.reverse`

***

### rowCount()

> **rowCount**(): `number`

Defined in: [api/node/typescript/models.ts:436](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L436)

Returns the number of entries in the model.

#### Returns

`number`

#### Inherited from

`NativeAdapterModel.rowCount`

***

### rowData()

> **rowData**(`row`): `T` \| `undefined`

Defined in: [api/node/typescript/models.ts:445](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L445)

Returns the data at the specified row.

#### Parameters

##### row

`number`

index in range 0..(rowCount() - 1).

#### Returns

`T` \| `undefined`

undefined if row is out of range otherwise the data.

#### Inherited from

`NativeAdapterModel.rowData`

***

### setRowData()

> **setRowData**(`row`, `data`): `void`

Defined in: [api/node/typescript/models.ts:455](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L455)

Stores the given data in the source model at the row that corresponds
to the given row index.

#### Parameters

##### row

`number`

index in range 0..(rowCount() - 1).

##### data

`T`

new data item to store on the given row index.

#### Returns

`void`

#### Inherited from

`NativeAdapterModel.setRowData`

***

### sort()

> **sort**(`compareFunction`): [`SortModel`](/latest/docs/node/api/classes/sortmodel/)\<`T`\>

Defined in: [api/node/typescript/models.ts:129](https://github.com/slint-ui/slint/blob/master/api/node/typescript/models.ts#L129)

Returns a new Model with the same rows as this model, ordered according to
`compareFunction`.

#### Parameters

##### compareFunction

(`a`, `b`) => `number`

compares two rows the same way the callback passed to
                        Array.prototype.sort does.

#### Returns

[`SortModel`](/latest/docs/node/api/classes/sortmodel/)\<`T`\>

a new [SortModel](/latest/docs/node/api/classes/sortmodel/) that wraps the current model.

#### Inherited from

`NativeAdapterModel.sort`