Skip to content

Commit 8fa78c8

Browse files
committed
update according 1.7.6
1 parent e802363 commit 8fa78c8

14 files changed

+71
-33
lines changed

src/content/docs/config/custom-service.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const slider = Widget.Slider({
117117
});
118118

119119
const label = Label({
120-
label: brightness.bind('screen-value').transform(v => `${v}`),
120+
label: brightness.bind('screen-value').as(v => `${v}`),
121121
setup: self => self.hook(brightness, (self, screenValue) => {
122122
// screenValue is the passed parameter from the 'screen-changed' signal
123123
self.label = screenValue ?? 0;

src/content/docs/config/first-widgets.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ const bar = Widget.Window({
196196
name: 'bar',
197197
anchor: ['top', 'left', 'right'],
198198
child: Widget.Label({
199-
label: myVariable.bind().transform(v => `value: ${v}`)
199+
label: myVariable.bind().as(v => `value: ${v}`)
200200
}),
201201
})
202202

@@ -227,7 +227,7 @@ pactl.connect('changed', ({ value }) => {
227227
})
228228

229229
const label = Widget.Label({
230-
label: pactl.bind().transform(({ count, msg }) => {
230+
label: pactl.bind().as(({ count, msg }) => {
231231
return `${msg} ${count}`
232232
}),
233233
})
@@ -250,7 +250,7 @@ of a single `value` they have more attributes and methods on them.
250250
const battery = await Service.import('battery')
251251

252252
const batteryProgress = Widget.CircularProgress({
253-
value: battery.bind('percent').transform(p => p / 100),
253+
value: battery.bind('percent').as(p => p / 100),
254254
child: Widget.Icon({
255255
icon: battery.bind('icon_name'),
256256
}),

src/content/docs/config/reactivity.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ and [Variables](./variables) that can be used inside constructors.
8181
Label({
8282
label: Battery
8383
.bind('percent')
84-
.transform(p => `${p}%`)
84+
.as(p => `${p}%`)
8585
})
8686
```
8787

@@ -91,7 +91,7 @@ const text = Variable('hello')
9191
Label({
9292
label: text
9393
.bind()
94-
.transform(v => `transformed ${v}`)
94+
.as(v => `transformed ${v}`)
9595
})
9696
```
9797

src/content/docs/config/services.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,30 @@ const widget = Widget.Label()
1717
self.label = 'new label'
1818
}, 'changed')
1919

20-
// [prop, Service, targetProp, transfrom = out => out]
20+
// [prop, Service, targetProp, transform = out => out]
2121
.bind('label', SomeService, 'service-prop', function(serviceProp) {
2222
return `transformed ${serviceProp}`
2323
})
2424
```
2525

2626
```js
2727
Widget.Label({
28-
label: someService.bind('service-prop').transfrom(serviceProp => {
28+
label: someService.bind('service-prop').as(serviceProp => {
2929
return `transformed ${serviceProp}`
3030
}),
3131
})
3232
```
3333

34+
Utility to have multiple bindings as one
35+
36+
```js
37+
Widget.Label({
38+
label: Utils.merge([service1.bind("prop1"), service2.bind("prop2")], (p1, p2) => {
39+
return `service1.prop1: ${p1}, service2.prop2: ${p2}`
40+
}),
41+
})
42+
```
43+
3444
Services can be also connected outside of widgets
3545

3646
```js

src/content/docs/config/subclassing-gtk-widgets.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function CounterButton(({ color = 'aqua', ...rest })) {
5151
const count = Variable(0);
5252

5353
const label = Widget.Label({
54-
label: count.bind().transform(v => `count: ${v}`),
54+
label: count.bind().as(v => `count: ${v}`),
5555
style: `color: ${color}`,
5656
});
5757

src/content/docs/config/utils.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,26 @@ proc.force_exit()
9090
```ts
9191
function readFile(file: string | Gio.File): string
9292
function readFileAsync(file: string | Gio.File): Promise<string>
93+
94+
function writeFileSync(string: string, path: string): Gio.File
95+
function writeFile(string: string, path: string): Promise<Gio.File>
9396
```
9497

95-
### Synchronously reading, returns a string
98+
### Synchronously
9699

97100
```js
98-
const contents = Utils.readFile('path-to-file')
101+
const contents = Utils.readFile('/path/to/file')
102+
103+
Utils.writeFileSync('/path/to/file', 'some content')
99104
```
100105

101-
### Asynchronously reading, returns a Promise
106+
### Asynchronously
102107

103108
```js
104109
Utils.readFileAsync('path-to-file')
105110
.then(content => print('contents of the file: ' + content))
106111
.catch(logError)
107-
```
108-
109-
### Asynchronously writing, returns a Promise
110112
111-
```js
112113
Utils.writeFile('Contents: Hi Mom', 'path-to-file')
113114
.then(file => print('file is the Gio.File'))
114115
.catch(err => print(err))
@@ -120,7 +121,6 @@ Utils.writeFile('Contents: Hi Mom', 'path-to-file')
120121
function monitorFile(
121122
path: string,
122123
callback?: (file: Gio.File, event: Gio.FileMonitorEvent) => void,
123-
type: 'file' | 'directory' = 'file',
124124
flags = Gio.FileMonitorFlags.NONE,
125125
): Gio.FileMonitor | null
126126
```

src/content/docs/config/variables.md

+28-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ myVar.value = 'new-value'
5050
myVar.setValue('new-value')
5151
```
5252

53+
:::caution
54+
using `setValue` will force a new value and thus signal `changed`,
55+
while setting `value` only signal if it gets a new value
56+
57+
```js
58+
const myVar = Variable({ key: "value" })
59+
const value = myVar.value
60+
value["new-key"] = "value"
61+
myVar.value = value // won't emit, because its still the same object
62+
myVar.setValue(value) // will emit the signal
63+
```
64+
65+
:::
66+
5367
### Getting its value
5468

5569
```js
@@ -87,7 +101,7 @@ const label = Widget.Label({
87101
label: myVar.bind(),
88102

89103
// optional transform method
90-
label: myVar.bind().transform(value => value.toString()),
104+
label: myVar.bind().as(value => value.toString()),
91105

92106
// hook to do more than an assignment on changed
93107
setup: self => self.hook(myVar, () => {
@@ -139,3 +153,16 @@ const ramProgress = Widget.CircularProgress({
139153
value: ram.bind()
140154
})
141155
```
156+
157+
## Derived Variables
158+
159+
```js
160+
const a = Variable(2)
161+
const b = Variable(3)
162+
163+
// first argument is a list of dependencies
164+
// second argument is a transform function
165+
const c = Utils.derive([a, b], (a, b) => {
166+
return a * b
167+
})
168+
```

src/content/docs/config/widgets.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ const progress = Widget.CircularProgress({
172172
'background-color: #131313;' + // set its bg color
173173
'color: aqua;', // set its fg color
174174

175-
value: battery.bind('percent').transform(p => p / 100),
175+
value: battery.bind('percent').as(p => p / 100),
176176
child: Widget.Icon({
177177
icon: battery.bind('icon-name'),
178178
}),

src/content/docs/services/battery.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const batteryProgress = Widget.CircularProgress({
2929
icon: battery.bind('icon_name')
3030
}),
3131
visible: battery.bind('available'),
32-
value: battery.bind('percent').transform(p => p > 0 ? p / 100 : 0),
33-
class_name: battery.bind('charging').transform(ch => ch ? 'charging' : ''),
32+
value: battery.bind('percent').as(p => p > 0 ? p / 100 : 0),
33+
class_name: battery.bind('charging').as(ch => ch ? 'charging' : ''),
3434
})
3535
```

src/content/docs/services/bluetooth.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const connectedList = Widget.Box({
5959
})
6060

6161
const indicator = Widget.Icon({
62-
icon: bluetooth.bind('enabled').transform(on =>
62+
icon: bluetooth.bind('enabled').as(on =>
6363
`bluetooth-${on ? 'active' : 'disabled'}-symbolic`),
6464
})
6565
```

src/content/docs/services/hyprland.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ title: Hyprland
88
* `urgent-window`: `(windowaddress: int)`
99
* `keyboard-layout`: `(keyboardname: string, layoutname: string)`
1010
* `submap`: `(name: string)`
11-
* `monitor-added`: `(name: string)`
12-
* `monitor-removed`: `(name: string)`
13-
* `workspace-added`: `(name: string)`
14-
* `workspace-removed`: `(name: string)`
11+
* `monitor-added`: `(name: number)`
12+
* `monitor-removed`: `(name: number)`
13+
* `workspace-added`: `(name: number)`
14+
* `workspace-removed`: `(name: number)`
1515
* `client-added`: `(address: string)`
1616
* `client-removed`: `(address: string)`
1717

@@ -27,7 +27,8 @@ title: Hyprland
2727
* `getMonitor`: `(id: number) => Monitor`
2828
* `getWorkspace`: `(id: number) => Workspace`
2929
* `getClient`: `(address: string) => Client`
30-
* `sendMessage`: `(msg: string) => Promise<string>`: send a message to the [hyprland socket](https://wiki.hyprland.org/IPC/#tmphyprhissocketsock)
30+
* `message`: `(msg: string) => string`: send a message to the [hyprland socket](https://wiki.hyprland.org/IPC/#tmphyprhissocketsock)
31+
* `messageAsync`: `(msg: string) => Promise<string>`: async version of message
3132

3233
## Active
3334

@@ -78,10 +79,10 @@ const hyprland = await Service.import('hyprland')
7879
const focusedTitle = Widget.Label({
7980
label: hyprland.active.client.bind('title'),
8081
visible: hyprland.active.client.bind('address')
81-
.transform(addr => !!addr),
82+
.as(addr => !!addr),
8283
})
8384

84-
const dispatch = ws => hyprland.sendMessage(`dispatch workspace ${ws}`);
85+
const dispatch = ws => hyprland.messageAsync(`dispatch workspace ${ws}`);
8586

8687
const Workspaces = () => Widget.EventBox({
8788
onScrollUp: () => dispatch('+1'),

src/content/docs/services/mpris.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ const Player = player => Widget.Button({
7575
})
7676

7777
const players = Widget.Box({
78-
children: mpris.bind('players').transform(p => p.map(Player))
78+
children: mpris.bind('players').as(p => p.map(Player))
7979
})
8080
```

src/content/docs/services/network.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const WifiIndicator = () => Widget.Box({
6868
}),
6969
Widget.Label({
7070
label: network.wifi.bind('ssid')
71-
.transform(ssid => ssid || 'Unknown'),
71+
.as(ssid => ssid || 'Unknown'),
7272
}),
7373
],
7474
})
@@ -82,6 +82,6 @@ const NetworkIndicator = () => Widget.Stack({
8282
['wifi', WifiIndicator()],
8383
['wired', WiredIndicator()],
8484
],
85-
shown: network.bind('primary').transform(p => p || 'wifi'),
85+
shown: network.bind('primary').as(p => p || 'wifi'),
8686
})
8787
```

src/content/docs/services/systemtray.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ const SysTrayItem = item => Widget.Button({
5959
});
6060

6161
const sysTray = Widget.Box({
62-
children: systemtray.bind('items').transform(i => i.map(SysTrayItem))
62+
children: systemtray.bind('items').as(i => i.map(SysTrayItem))
6363
})
6464
```

0 commit comments

Comments
 (0)