Skip to content

Commit

Permalink
add migration guide (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 authored Oct 10, 2021
1 parent 39b7f95 commit 77ba542
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions docs/api/v0_3_0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# v0.3.0 migration guide

Version 0.3.0 of magicgui introduced some changes to the events and callbacks API.
See https://github.com/napari/magicgui/pull/253 for details

## Callbacks now receive the value directly, instead of an `Event` object

magicgui 0.3.0 is now using [psygnal](https://github.com/tlambert03/psygnal)
as its event/callback handler.

Callbacks connected to `widget.changed` (and other event emitters) now receive the
value(s) directly, instead of an event object:

```python
# before:
@widget.changed.connect
def my_callback(event):
new_value = event.value

# now becomes
@widget.changed.connect
def my_callback(value):
new_value = value

# note also that psygnal lets you accept _less_
# arguments than the emitter provides
# so this also works fine
@widget.changed.connect
def my_callback():
# something that didn't need the value
...
```

## Event emitters take no keyword arguments

For the few packages who were manually emitting change events,
you should no longer provide the `value=` keyword when emitting.

```python
# before:
widget.changed(value='whatever')

# now becomes
widget.changed.emit('whatever')
# OR (if you prefer the direct __call__ syntax)
widget.changed('whatever')
```

0 comments on commit 77ba542

Please sign in to comment.