dolphin-client 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -16
- package/dist/dolphin-client.js +450 -41
- package/dist/dolphin-client.min.js +18 -18
- package/dist/index.cjs +450 -41
- package/dist/index.js +450 -41
- package/dist/store.d.ts +84 -10
- package/fulltutorial.md +108 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -178,8 +178,9 @@ Apply strong validation rules to inputs and display errors directly in the UI wi
|
|
|
178
178
|
```
|
|
179
179
|
|
|
180
180
|
### 4. Global State & Declarative Store Actions (No-JS Actions!)
|
|
181
|
-
Manage local stores
|
|
181
|
+
Manage local stores, calculate math, toggle boolean logic, and run database collection operations **directly in HTML attributes**:
|
|
182
182
|
|
|
183
|
+
#### UI State Management:
|
|
183
184
|
```html
|
|
184
185
|
<!-- 1. Auto-sync inputs directly into store key 'app.username' -->
|
|
185
186
|
<input data-store-write="app.username" placeholder="Type name..." />
|
|
@@ -193,34 +194,77 @@ Manage local stores and run complex calculations, conditions, and toggles **dire
|
|
|
193
194
|
<button data-store-click="app.count = (app.count || 0) - 1">-</button>
|
|
194
195
|
</div>
|
|
195
196
|
|
|
196
|
-
<!-- 3. Complex Calculations
|
|
197
|
-
<button data-store-click="
|
|
198
|
-
app.area = 3.14159 * (app.radius * app.radius);
|
|
199
|
-
app.circumference = 2 * 3.14159 * app.radius
|
|
200
|
-
">
|
|
201
|
-
Calculate Circle
|
|
202
|
-
</button>
|
|
203
|
-
|
|
204
|
-
<!-- 4. Logic Toggles (e.g. Dark Mode Toggle) -->
|
|
197
|
+
<!-- 3. Complex Calculations & Toggles -->
|
|
198
|
+
<button data-store-click="app.area = 3.14159 * (app.radius * app.radius)">Calculate Area</button>
|
|
205
199
|
<button data-store-click="app.darkMode = !app.darkMode">Toggle Dark Mode</button>
|
|
206
200
|
```
|
|
207
201
|
|
|
202
|
+
#### Database Store CRUD & Filters (New in v2.0!):
|
|
203
|
+
```html
|
|
204
|
+
<!-- 1. Initialize or sync the database collection -->
|
|
205
|
+
<dolphin-store name="products"></dolphin-store>
|
|
206
|
+
|
|
207
|
+
<!-- 2. Search and filter the collection directly from HTML inputs -->
|
|
208
|
+
<input placeholder="Search products..." data-store-input="products.search(this.value)" />
|
|
209
|
+
|
|
210
|
+
<select data-store-change="products.filter('category', this.value)">
|
|
211
|
+
<option value="">All Categories</option>
|
|
212
|
+
<option value="electronics">Electronics</option>
|
|
213
|
+
</select>
|
|
214
|
+
|
|
215
|
+
<!-- 3. Trigger sorting or reset filters -->
|
|
216
|
+
<button data-store-click="products.sort('price', false)">Sort by Price Desc</button>
|
|
217
|
+
<button data-store-click="products.clearFilters()">Reset</button>
|
|
218
|
+
|
|
219
|
+
<!-- 4. Execute database mutations (DOM updates automatically!) -->
|
|
220
|
+
<div data-rt-bind="store/products" data-rt-template="#product-list"></div>
|
|
221
|
+
<template id="product-list">
|
|
222
|
+
{#each items as item}
|
|
223
|
+
<div>
|
|
224
|
+
<span>{{item.name}}</span>
|
|
225
|
+
<button data-store-click="products.deleteById(item.id)">Delete</button>
|
|
226
|
+
</div>
|
|
227
|
+
{/each}
|
|
228
|
+
</template>
|
|
229
|
+
```
|
|
230
|
+
|
|
208
231
|
### 5. JavaScript Store API & React Integration
|
|
209
|
-
Query and filter dynamic collections programmatically in JS or sync
|
|
232
|
+
Query and filter dynamic database collections programmatically in JS, run optimistic updates, track loading state, or sync with React with zero state hooks:
|
|
210
233
|
|
|
211
234
|
```javascript
|
|
212
235
|
// Access the reactive store (auto-fetches GET /users and subscribes to WS db:sync/users)
|
|
213
236
|
const users = dolphin.store.users;
|
|
214
237
|
|
|
215
|
-
//
|
|
216
|
-
const
|
|
238
|
+
// 1. DataEngine chainable filtering, text search, ranges, and sorting (New in v2.0)
|
|
239
|
+
const results = users
|
|
240
|
+
.search('admin', ['role', 'name'])
|
|
241
|
+
.filter('active', true)
|
|
242
|
+
.range('age', 18, 65)
|
|
243
|
+
.sort('name', true); // asc=true
|
|
244
|
+
|
|
245
|
+
console.log("Filtered users:", results.items);
|
|
246
|
+
|
|
247
|
+
// 2. Pagination (New in v2.0)
|
|
248
|
+
const pageData = users.page(1, 10); // Page 1, size 10
|
|
249
|
+
console.log(`Page ${pageData.page} of ${pageData.pages}`, pageData.data);
|
|
250
|
+
|
|
251
|
+
// 3. Optimistic Updates with Rollback (New in v2.0)
|
|
252
|
+
// Updates the UI instantly, calls API, and automatically rolls back if API fails
|
|
253
|
+
await users.optimisticUpdate(101, { status: 'suspended' }, () => {
|
|
254
|
+
return dolphin.api.put('/users/101', { status: 'suspended' });
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
// 4. Per-Item Loading State Tracking (New in v2.0)
|
|
258
|
+
users.trackStart(101); // Mark user 101 as processing
|
|
259
|
+
console.log(users.isLoading(101)); // true
|
|
260
|
+
users.trackEnd(101); // Remove from tracking
|
|
217
261
|
|
|
218
|
-
// Subscribe to store changes manually
|
|
262
|
+
// 5. Subscribe to store changes manually
|
|
219
263
|
const unsubscribe = dolphin.store.subscribe(() => {
|
|
220
|
-
console.log("
|
|
264
|
+
console.log("Store updated, current users:", users.items);
|
|
221
265
|
});
|
|
222
266
|
|
|
223
|
-
// Clean up when no longer needed to prevent memory leaks
|
|
267
|
+
// Clean up when no longer needed to prevent memory leaks (WS unsubscribe fix)
|
|
224
268
|
dolphin.store.destroy();
|
|
225
269
|
```
|
|
226
270
|
|