@placeos/ts-client 4.2.0 → 4.2.2

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.
@@ -16,8 +16,14 @@ export declare class PlaceModuleBinding {
16
16
  /**
17
17
  * Get binding with the given name
18
18
  * @param name Name of the binding
19
+ * @deprecated Use `variable` instead
19
20
  */
20
21
  binding<T = any>(name: string): PlaceVariableBinding<T>;
22
+ /**
23
+ * Get binding with the given name
24
+ * @param name Name of the binding
25
+ */
26
+ variable<T = any>(name: string): PlaceVariableBinding<T>;
21
27
  /**
22
28
  * Execute method on the engine module
23
29
  * @param method Name of the method
@@ -20,10 +20,12 @@ export declare class PlaceVariableBinding<T = any> {
20
20
  */
21
21
  listen(): Observable<T>;
22
22
  /**
23
- * Subscribe to changes of the variable's binding value
23
+ * Subscribe to changes of the variable's binding value.
24
+ * Note: Initial value emitted may be `undefined`
24
25
  * @param next Callback for changes to the bindings value
25
26
  */
26
27
  subscribe(next: (value: T) => void): Subscription;
28
+ bindThenSubscribe(next: (value: T) => void): Subscription;
27
29
  /**
28
30
  * Bind to the status variable's value
29
31
  */
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.2.0",
2
+ "version": "4.2.2",
3
3
  "license": "MIT",
4
4
  "name": "@placeos/ts-client",
5
5
  "author": "Alex Sorafumo <alex@place.tech>",
@@ -38,6 +38,7 @@ export class PlaceModuleBinding {
38
38
  /**
39
39
  * Get binding with the given name
40
40
  * @param name Name of the binding
41
+ * @deprecated Use `variable` instead
41
42
  */
42
43
  public binding<T = any>(name: string) {
43
44
  if (!this._bindings[name]) {
@@ -46,6 +47,17 @@ export class PlaceModuleBinding {
46
47
  return this._bindings[name] as PlaceVariableBinding<T>;
47
48
  }
48
49
 
50
+ /**
51
+ * Get binding with the given name
52
+ * @param name Name of the binding
53
+ */
54
+ public variable<T = any>(name: string) {
55
+ if (!this._bindings[name]) {
56
+ this._bindings[name] = new PlaceVariableBinding<T>(this, name);
57
+ }
58
+ return this._bindings[name] as PlaceVariableBinding<T>;
59
+ }
60
+
49
61
  /**
50
62
  * Execute method on the engine module
51
63
  * @param method Name of the method
@@ -72,13 +72,23 @@ export class PlaceVariableBinding<T = any> {
72
72
  }
73
73
 
74
74
  /**
75
- * Subscribe to changes of the variable's binding value
75
+ * Subscribe to changes of the variable's binding value.
76
+ * Note: Initial value emitted may be `undefined`
76
77
  * @param next Callback for changes to the bindings value
77
78
  */
78
79
  public subscribe(next: (value: T) => void): Subscription {
79
80
  return this.listen().subscribe(next);
80
81
  }
81
82
 
83
+ public bindThenSubscribe(next: (value: T) => void): Subscription {
84
+ const unbind = this.bind();
85
+ return this.listen().subscribe({
86
+ next,
87
+ complete: () => unbind(),
88
+ error: () => unbind(),
89
+ });
90
+ }
91
+
82
92
  /**
83
93
  * Bind to the status variable's value
84
94
  */