Skip to content

Commit fdd1896

Browse files
committed
Update docs
1 parent ba210c6 commit fdd1896

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

Sources/Normalization/Documentation.docc/Normalization.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ State management plays a crucial role in building efficient and maintainable app
66

77
Normalization is the process of structuring data in a way that eliminates redundancy and ensures data consistency. It is essential in state-management libraries because it significantly reduces the computational complexity of operations and makes it easier to manage the state.
88

9-
Docs:
10-
- [VergeNormalization](https://swiftpackageindex.com/VergeGroup/swift-Verge/main/documentation/vergenormalization)
11-
- [VergeNormalizationDerived](https://swiftpackageindex.com/VergeGroup/swift-Verge/main/documentation/vergenormalizationderived)
12-
139
Let's take a look at an example to illustrate the difference between normalized and denormalized data structures.
10+
11+
[Redux's normalization explanations](https://redux.js.org/usage/structuring-reducers/normalizing-state-shape) are also useful to understatnd the concept of normalization.
1412

1513
**Denormalized data structure:**
1614

@@ -65,7 +63,7 @@ entities:
6563
6664
In the normalized structure, author data is stored separately from posts, eliminating data redundancy and ensuring data consistency. The relationship between posts and authors is represented by the `authorId` field in the posts.
6765

68-
VergeORM is designed to handle normalization in state-management libraries effectively. By leveraging VergeORM, you can simplify your state management, reduce the computational complexity of operations, and improve the overall performance and maintainability of your application.
66+
Normalization is designed to handle normalization in state-management libraries effectively. By leveraging Normalization, you can simplify your state management, reduce the computational complexity of operations, and improve the overall performance and maintainability of your application.
6967

7068
**Defining Entities**
7169

@@ -119,32 +117,32 @@ struct Database {
119117
Embed the `Database` in your application's state:
120118

121119
```swift
122-
struct RootState: StateType {
120+
struct RootState {
123121
var database: Database = .init()
124122
}
125123
```
126124

127125
**Storing and Querying Entities**
128126

129-
Here's an example of how to store and query entities using a `store` property
127+
Writing
130128

131129
```swift
132-
// Storing entities
133-
store.commit {
134-
$0.database.performBatchUpdates { context in
135-
let authors = (0..<10).map { i in
136-
Author(rawID: "\(i)")
137-
}
138-
let result = context.modifying.author.insert(authors)
130+
var state: RootState
131+
132+
state.database.performBatchUpdates { context in
133+
let authors = (0..<10).map { i in
134+
Author(rawID: "\(i)")
139135
}
136+
let result = context.modifying.author.insert(authors)
140137
}
141-
142-
// Querying entities
143-
let book = store.state.database.db.book.find(by: .init("1"))
144-
let author = store.state.database.db.author.find(by: .init("1"))
145138
```
146139

147-
In this example, we use `store.commit` to perform batch updates on the database. We insert a new set of authors into the `author` entity table. Then, we use `store.state.database.db` to query the `book` and `author` entities by their identifiers.
140+
Reading
141+
142+
```swift
143+
let book = state.database.db.book.find(by: .init("1"))
144+
let author = state.database.db.author.find(by: .init("1"))
145+
```
148146

149147
By using VergeNormalization, you can efficiently manage your application state with a normalized data structure, which simplifies your state management, reduces the computational complexity of operations, and improves the overall performance and maintainability of your application.
150148

0 commit comments

Comments
 (0)