@view-models/core 1.2.0 → 2.0.0

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.
@@ -13,14 +13,14 @@ export type Updater<T> = (currentState: T) => T;
13
13
  * @template T - The state type
14
14
  * @param state - The new state
15
15
  */
16
- export type ViewModelListener<T> = (state: T) => void;
16
+ export type ViewModelListener = () => void;
17
17
  /**
18
18
  * Abstract base class for creating reactive view models.
19
19
  *
20
20
  * A ViewModel manages state and notifies subscribers when the state changes.
21
21
  * Extend this class to create your own view models with custom business logic.
22
22
  *
23
- * @template T - The state type
23
+ * @template S - The state type
24
24
  *
25
25
  * @example
26
26
  * ```typescript
@@ -43,7 +43,7 @@ export type ViewModelListener<T> = (state: T) => void;
43
43
  * counter.increment(); // Logs: Count: 1
44
44
  * ```
45
45
  */
46
- export declare abstract class ViewModel<T> {
46
+ export declare abstract class ViewModel<S> {
47
47
  private _listeners;
48
48
  /**
49
49
  * Subscribe to state changes.
@@ -63,14 +63,14 @@ export declare abstract class ViewModel<T> {
63
63
  * unsubscribe();
64
64
  * ```
65
65
  */
66
- subscribe(listener: ViewModelListener<T>): () => void;
66
+ subscribe(listener: ViewModelListener): () => void;
67
67
  private _state;
68
68
  /**
69
69
  * Create a new ViewModel with the given initial state.
70
70
  *
71
71
  * @param initialState - The initial state of the view model
72
72
  */
73
- constructor(initialState: T);
73
+ constructor(initialState: S);
74
74
  /**
75
75
  * Update the state and notify all subscribers.
76
76
  *
@@ -88,12 +88,12 @@ export declare abstract class ViewModel<T> {
88
88
  * }));
89
89
  * ```
90
90
  */
91
- protected update(updater: Updater<T>): void;
91
+ protected update(updater: Updater<S>): void;
92
92
  /**
93
93
  * Get the current state.
94
94
  *
95
95
  * @returns The current state
96
96
  */
97
- get state(): T;
97
+ get state(): S;
98
98
  }
99
99
  //# sourceMappingURL=ViewModel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ViewModel.d.ts","sourceRoot":"","sources":["../src/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AAS,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAQpC;;;;OAIG;IACH,IAAI,KAAK,IAAI,CAAC,CAEb;CACF"}
package/dist/ViewModel.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * A ViewModel manages state and notifies subscribers when the state changes.
5
5
  * Extend this class to create your own view models with custom business logic.
6
6
  *
7
- * @template T - The state type
7
+ * @template S - The state type
8
8
  *
9
9
  * @example
10
10
  * ```typescript
@@ -81,7 +81,7 @@ export class ViewModel {
81
81
  update(updater) {
82
82
  this._state = updater(this._state);
83
83
  for (const listener of this._listeners) {
84
- listener(this._state);
84
+ listener();
85
85
  }
86
86
  }
87
87
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@view-models/core",
3
- "version": "1.2.0",
3
+ "version": "2.0.0",
4
4
  "description": "A lightweight, framework-agnostic library for building reactive view models with TypeScript",
5
5
  "keywords": [
6
6
  "view",
package/src/ViewModel.ts CHANGED
@@ -14,7 +14,7 @@ export type Updater<T> = (currentState: T) => T;
14
14
  * @template T - The state type
15
15
  * @param state - The new state
16
16
  */
17
- export type ViewModelListener<T> = (state: T) => void;
17
+ export type ViewModelListener = () => void;
18
18
 
19
19
  /**
20
20
  * Abstract base class for creating reactive view models.
@@ -22,7 +22,7 @@ export type ViewModelListener<T> = (state: T) => void;
22
22
  * A ViewModel manages state and notifies subscribers when the state changes.
23
23
  * Extend this class to create your own view models with custom business logic.
24
24
  *
25
- * @template T - The state type
25
+ * @template S - The state type
26
26
  *
27
27
  * @example
28
28
  * ```typescript
@@ -45,8 +45,8 @@ export type ViewModelListener<T> = (state: T) => void;
45
45
  * counter.increment(); // Logs: Count: 1
46
46
  * ```
47
47
  */
48
- export abstract class ViewModel<T> {
49
- private _listeners: Set<ViewModelListener<T>> = new Set();
48
+ export abstract class ViewModel<S> {
49
+ private _listeners: Set<ViewModelListener> = new Set();
50
50
 
51
51
  /**
52
52
  * Subscribe to state changes.
@@ -66,21 +66,21 @@ export abstract class ViewModel<T> {
66
66
  * unsubscribe();
67
67
  * ```
68
68
  */
69
- subscribe(listener: ViewModelListener<T>): () => void {
69
+ subscribe(listener: ViewModelListener): () => void {
70
70
  this._listeners.add(listener);
71
71
  return () => {
72
72
  this._listeners.delete(listener);
73
73
  };
74
74
  }
75
75
 
76
- private _state: T;
76
+ private _state: S;
77
77
 
78
78
  /**
79
79
  * Create a new ViewModel with the given initial state.
80
80
  *
81
81
  * @param initialState - The initial state of the view model
82
82
  */
83
- constructor(initialState: T) {
83
+ constructor(initialState: S) {
84
84
  this._state = initialState;
85
85
  }
86
86
 
@@ -101,11 +101,11 @@ export abstract class ViewModel<T> {
101
101
  * }));
102
102
  * ```
103
103
  */
104
- protected update(updater: Updater<T>) {
104
+ protected update(updater: Updater<S>) {
105
105
  this._state = updater(this._state);
106
106
 
107
107
  for (const listener of this._listeners) {
108
- listener(this._state);
108
+ listener();
109
109
  }
110
110
  }
111
111
 
@@ -114,7 +114,7 @@ export abstract class ViewModel<T> {
114
114
  *
115
115
  * @returns The current state
116
116
  */
117
- get state(): T {
117
+ get state(): S {
118
118
  return this._state;
119
119
  }
120
120
  }