mobx-mantle 0.3.6 → 0.3.7

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.
Files changed (2) hide show
  1. package/README.md +13 -48
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MobX Mantle
2
2
 
3
- A lightweight library for building React components with a class-based API and MobX reactivity built in. Get full access to the React ecosystem, with better access to vanilla JS libraries, and simpler overall DX for both.
3
+ A lightweight library for building React components with a familiar class-based API and MobX reactivity built in. Get full access to the React ecosystem, with better access to vanilla JS libraries, and simpler overall DX for both.
4
4
 
5
5
  ## Why
6
6
 
@@ -79,8 +79,8 @@ toggle(id: number) { // automatically bound to this
79
79
 
80
80
  **React to changes explicitly:**
81
81
  ```tsx
82
- onMount() {
83
- return reaction(
82
+ onCreate() {
83
+ this.watch(
84
84
  () => this.props.filter,
85
85
  (filter) => this.applyFilter(filter)
86
86
  );
@@ -159,6 +159,8 @@ onCreate() {
159
159
  }
160
160
  ```
161
161
 
162
+ `this.watch` wraps MobX's `reaction` with automatic lifecycle disposal. For advanced MobX patterns (`autorun`, `when`, custom schedulers), use `reaction` directly and return a dispose function from `onMount`.
163
+
162
164
  ### Props Reactivity
163
165
 
164
166
  `this.props` is reactive: your component re-renders when accessed props change.
@@ -370,42 +372,6 @@ function Parent() {
370
372
  }
371
373
  ```
372
374
 
373
- ## Reactions
374
-
375
- ```tsx
376
- class SearchView extends View<Props> {
377
- query = '';
378
- results: string[] = [];
379
-
380
- onMount() {
381
- const dispose = reaction(
382
- () => this.query,
383
- async (query) => {
384
- if (query.length > 2) {
385
- this.results = await searchApi(query);
386
- }
387
- },
388
- { delay: 300 }
389
- );
390
-
391
- return dispose;
392
- }
393
-
394
- setQuery(e: React.ChangeEvent<HTMLInputElement>) {
395
- this.query = e.target.value;
396
- }
397
-
398
- render() {
399
- return (
400
- <div>
401
- <input value={this.query} onChange={this.setQuery} />
402
- <ul>{this.results.map(r => <li key={r}>{r}</li>)}</ul>
403
- </div>
404
- );
405
- }
406
- }
407
- ```
408
-
409
375
  ## React Hooks
410
376
 
411
377
  Hooks work inside `render()`:
@@ -439,20 +405,19 @@ class ChartView extends View<{ data: number[] }> {
439
405
  containerRef = this.ref<HTMLDivElement>();
440
406
  chart: Chart | null = null;
441
407
 
408
+ onCreate() {
409
+ this.watch(
410
+ () => this.props.data,
411
+ (data) => this.chart?.update(data)
412
+ );
413
+ }
414
+
442
415
  onMount() {
443
416
  this.chart = new Chart(this.containerRef.current!, {
444
417
  data: this.props.data,
445
418
  });
446
419
 
447
- const dispose = reaction(
448
- () => this.props.data,
449
- (data) => this.chart?.update(data)
450
- );
451
-
452
- return () => {
453
- dispose();
454
- this.chart?.destroy();
455
- };
420
+ return () => this.chart?.destroy();
456
421
  }
457
422
 
458
423
  render() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobx-mantle",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "A lightweight library for building React components with a familiar class-based API and MobX reactivity built in.",
5
5
  "author": "Craig Albert <me@craigalbert.com>",
6
6
  "repository": {