Skip to content

Commit 244912e

Browse files
committed
RDoc-3547 Clear session: fix article (Node.js)
1 parent 0290d3c commit 244912e

File tree

5 files changed

+260
-95
lines changed

5 files changed

+260
-95
lines changed

docs/client-api/session/how-to/_clear-a-session-nodejs.mdx

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,65 @@ import Tabs from '@theme/Tabs';
33
import TabItem from '@theme/TabItem';
44
import CodeBlock from '@theme/CodeBlock';
55

6-
To clear session state, stop tracking entities, and remove all pending commands,
7-
use the `clear()` method from the `advanced` session operations.
6+
<Admonition type="note" title="">
87

9-
## Syntax
8+
* Use the `clear()` method to clear the session’s state:
9+
it **removes ALL tracked entities** and **cancels ALL pending operations** (e.g., _store_, _delete_).
10+
This is useful when you need to discard all tracked changes and reset the session state.
11+
12+
* To remove only a **single entity** from tracking, see [Evict a single entity](../../../client-api/session/how-to/evict-entity-from-a-session.mdx).
1013

11-
<TabItem value="clear_1" label="clear_1">
12-
<CodeBlock language="js">
13-
{`session.advanced.clear();
14-
`}
15-
</CodeBlock>
16-
</TabItem>
14+
* In this article:
15+
* [Clear the session's state](../../../client-api/session/how-to/clear-a-session.mdx#clear-the-sessions-state)
16+
* [Syntax](../../../client-api/session/how-to/clear-a-session.mdx#syntax)
17+
18+
</Admonition>
19+
20+
---
21+
22+
## Clear the session's state
23+
24+
<TabItem value="sync_session" label="sync_session">
25+
```js
26+
const session = store.openSession();
27+
28+
// Store a new employee
29+
class Employee {
30+
constructor(firstName, lastName) {
31+
this.firstName = firstName;
32+
this.lastName = lastName;
33+
}
34+
}
35+
const newEmployee = new Employee("John", "Doe");
36+
await session.store(newEmployee, "employees/1");
37+
38+
// Load an existing employee and modify it
39+
const existingEmployee = await session.load("employees/2");
40+
existingEmployee.lastName = "UpdatedLastName";
1741

18-
## Example
42+
// Load another employee and mark for deletion
43+
const employeeToDelete = await session.load("employees/3");
44+
session.delete(employeeToDelete);
1945

20-
<TabItem value="clear_2" label="clear_2">
21-
<CodeBlock language="js">
22-
{`const employee = new Employee();
23-
employee.firstName = "John";
24-
employee.lastName = "Doe";
25-
await session.store(employee);
46+
// At this point:
47+
// * employees/1 is pending insert
48+
// * employees/2 is pending update
49+
// * employees/3 is pending delete
2650

51+
// Clear the session state
52+
// this will remove all tracking and pending operations
2753
session.advanced.clear();
2854

29-
await session.saveChanges(); // nothing will hapen
30-
`}
31-
</CodeBlock>
55+
// saveChanges does nothing - all operations were discarded
56+
await session.saveChanges();
57+
```
3258
</TabItem>
3359

60+
## Syntax
61+
62+
<TabItem value="" label="">
63+
```js
64+
session.advanced.clear();
65+
```
66+
</TabItem>
3467

versioned_docs/version-5.4/client-api/session/how-to/_clear-a-session-nodejs.mdx

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,65 @@ import Tabs from '@theme/Tabs';
33
import TabItem from '@theme/TabItem';
44
import CodeBlock from '@theme/CodeBlock';
55

6-
To clear session state, stop tracking entities, and remove all pending commands,
7-
use the `clear()` method from the `advanced` session operations.
6+
<Admonition type="note" title="">
87

9-
## Syntax
8+
* Use the `clear()` method to clear the session’s state:
9+
it **removes ALL tracked entities** and **cancels ALL pending operations** (e.g., _store_, _delete_).
10+
This is useful when you need to discard all tracked changes and reset the session state.
11+
12+
* To remove only a **single entity** from tracking, see [Evict a single entity](../../../client-api/session/how-to/evict-entity-from-a-session.mdx).
1013

11-
<TabItem value="clear_1" label="clear_1">
12-
<CodeBlock language="js">
13-
{`session.advanced.clear();
14-
`}
15-
</CodeBlock>
16-
</TabItem>
14+
* In this article:
15+
* [Clear the session's state](../../../client-api/session/how-to/clear-a-session.mdx#clear-the-sessions-state)
16+
* [Syntax](../../../client-api/session/how-to/clear-a-session.mdx#syntax)
17+
18+
</Admonition>
19+
20+
---
21+
22+
## Clear the session's state
23+
24+
<TabItem value="sync_session" label="sync_session">
25+
```js
26+
const session = store.openSession();
27+
28+
// Store a new employee
29+
class Employee {
30+
constructor(firstName, lastName) {
31+
this.firstName = firstName;
32+
this.lastName = lastName;
33+
}
34+
}
35+
const newEmployee = new Employee("John", "Doe");
36+
await session.store(newEmployee, "employees/1");
37+
38+
// Load an existing employee and modify it
39+
const existingEmployee = await session.load("employees/2");
40+
existingEmployee.lastName = "UpdatedLastName";
1741

18-
## Example
42+
// Load another employee and mark for deletion
43+
const employeeToDelete = await session.load("employees/3");
44+
session.delete(employeeToDelete);
1945

20-
<TabItem value="clear_2" label="clear_2">
21-
<CodeBlock language="js">
22-
{`const employee = new Employee();
23-
employee.firstName = "John";
24-
employee.lastName = "Doe";
25-
await session.store(employee);
46+
// At this point:
47+
// * employees/1 is pending insert
48+
// * employees/2 is pending update
49+
// * employees/3 is pending delete
2650

51+
// Clear the session state
52+
// this will remove all tracking and pending operations
2753
session.advanced.clear();
2854

29-
await session.saveChanges(); // nothing will hapen
30-
`}
31-
</CodeBlock>
55+
// saveChanges does nothing - all operations were discarded
56+
await session.saveChanges();
57+
```
3258
</TabItem>
3359

60+
## Syntax
61+
62+
<TabItem value="" label="">
63+
```js
64+
session.advanced.clear();
65+
```
66+
</TabItem>
3467

versioned_docs/version-6.0/client-api/session/how-to/_clear-a-session-nodejs.mdx

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,65 @@ import Tabs from '@theme/Tabs';
33
import TabItem from '@theme/TabItem';
44
import CodeBlock from '@theme/CodeBlock';
55

6-
To clear session state, stop tracking entities, and remove all pending commands,
7-
use the `clear()` method from the `advanced` session operations.
6+
<Admonition type="note" title="">
87

9-
## Syntax
8+
* Use the `clear()` method to clear the session’s state:
9+
it **removes ALL tracked entities** and **cancels ALL pending operations** (e.g., _store_, _delete_).
10+
This is useful when you need to discard all tracked changes and reset the session state.
11+
12+
* To remove only a **single entity** from tracking, see [Evict a single entity](../../../client-api/session/how-to/evict-entity-from-a-session.mdx).
1013

11-
<TabItem value="clear_1" label="clear_1">
12-
<CodeBlock language="js">
13-
{`session.advanced.clear();
14-
`}
15-
</CodeBlock>
16-
</TabItem>
14+
* In this article:
15+
* [Clear the session's state](../../../client-api/session/how-to/clear-a-session.mdx#clear-the-sessions-state)
16+
* [Syntax](../../../client-api/session/how-to/clear-a-session.mdx#syntax)
17+
18+
</Admonition>
19+
20+
---
21+
22+
## Clear the session's state
23+
24+
<TabItem value="sync_session" label="sync_session">
25+
```js
26+
const session = store.openSession();
27+
28+
// Store a new employee
29+
class Employee {
30+
constructor(firstName, lastName) {
31+
this.firstName = firstName;
32+
this.lastName = lastName;
33+
}
34+
}
35+
const newEmployee = new Employee("John", "Doe");
36+
await session.store(newEmployee, "employees/1");
37+
38+
// Load an existing employee and modify it
39+
const existingEmployee = await session.load("employees/2");
40+
existingEmployee.lastName = "UpdatedLastName";
1741

18-
## Example
42+
// Load another employee and mark for deletion
43+
const employeeToDelete = await session.load("employees/3");
44+
session.delete(employeeToDelete);
1945

20-
<TabItem value="clear_2" label="clear_2">
21-
<CodeBlock language="js">
22-
{`const employee = new Employee();
23-
employee.firstName = "John";
24-
employee.lastName = "Doe";
25-
await session.store(employee);
46+
// At this point:
47+
// * employees/1 is pending insert
48+
// * employees/2 is pending update
49+
// * employees/3 is pending delete
2650

51+
// Clear the session state
52+
// this will remove all tracking and pending operations
2753
session.advanced.clear();
2854

29-
await session.saveChanges(); // nothing will hapen
30-
`}
31-
</CodeBlock>
55+
// saveChanges does nothing - all operations were discarded
56+
await session.saveChanges();
57+
```
3258
</TabItem>
3359

60+
## Syntax
61+
62+
<TabItem value="" label="">
63+
```js
64+
session.advanced.clear();
65+
```
66+
</TabItem>
3467

versioned_docs/version-6.2/client-api/session/how-to/_clear-a-session-nodejs.mdx

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,65 @@ import Tabs from '@theme/Tabs';
33
import TabItem from '@theme/TabItem';
44
import CodeBlock from '@theme/CodeBlock';
55

6-
To clear session state, stop tracking entities, and remove all pending commands,
7-
use the `clear()` method from the `advanced` session operations.
6+
<Admonition type="note" title="">
87

9-
## Syntax
8+
* Use the `clear()` method to clear the session’s state:
9+
it **removes ALL tracked entities** and **cancels ALL pending operations** (e.g., _store_, _delete_).
10+
This is useful when you need to discard all tracked changes and reset the session state.
11+
12+
* To remove only a **single entity** from tracking, see [Evict a single entity](../../../client-api/session/how-to/evict-entity-from-a-session.mdx).
1013

11-
<TabItem value="clear_1" label="clear_1">
12-
<CodeBlock language="js">
13-
{`session.advanced.clear();
14-
`}
15-
</CodeBlock>
16-
</TabItem>
14+
* In this article:
15+
* [Clear the session's state](../../../client-api/session/how-to/clear-a-session.mdx#clear-the-sessions-state)
16+
* [Syntax](../../../client-api/session/how-to/clear-a-session.mdx#syntax)
17+
18+
</Admonition>
19+
20+
---
21+
22+
## Clear the session's state
23+
24+
<TabItem value="sync_session" label="sync_session">
25+
```js
26+
const session = store.openSession();
27+
28+
// Store a new employee
29+
class Employee {
30+
constructor(firstName, lastName) {
31+
this.firstName = firstName;
32+
this.lastName = lastName;
33+
}
34+
}
35+
const newEmployee = new Employee("John", "Doe");
36+
await session.store(newEmployee, "employees/1");
37+
38+
// Load an existing employee and modify it
39+
const existingEmployee = await session.load("employees/2");
40+
existingEmployee.lastName = "UpdatedLastName";
1741

18-
## Example
42+
// Load another employee and mark for deletion
43+
const employeeToDelete = await session.load("employees/3");
44+
session.delete(employeeToDelete);
1945

20-
<TabItem value="clear_2" label="clear_2">
21-
<CodeBlock language="js">
22-
{`const employee = new Employee();
23-
employee.firstName = "John";
24-
employee.lastName = "Doe";
25-
await session.store(employee);
46+
// At this point:
47+
// * employees/1 is pending insert
48+
// * employees/2 is pending update
49+
// * employees/3 is pending delete
2650

51+
// Clear the session state
52+
// this will remove all tracking and pending operations
2753
session.advanced.clear();
2854

29-
await session.saveChanges(); // nothing will hapen
30-
`}
31-
</CodeBlock>
55+
// saveChanges does nothing - all operations were discarded
56+
await session.saveChanges();
57+
```
3258
</TabItem>
3359

60+
## Syntax
61+
62+
<TabItem value="" label="">
63+
```js
64+
session.advanced.clear();
65+
```
66+
</TabItem>
3467

0 commit comments

Comments
 (0)