mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 18:58:36 +00:00
Add a reset function to the model notifier
This commit is contained in:
parent
2b93504b93
commit
f5030cff06
8 changed files with 67 additions and 4 deletions
|
@ -120,6 +120,7 @@ When such an object is set to a model property, it gets a new `notify` object wi
|
|||
* `rowDataChanged(index)`: notify the view that the row was changed.
|
||||
* `rowAdded(index, count)`: notify the view that rows were added.
|
||||
* `rowRemoved(index, count)`: notify the view that a row were removed.
|
||||
* `reset()`: notify the view that everything may have changed.
|
||||
|
||||
As an example, here is the implementation of the `ArrayModel` (which is available as `slint.ArrayModel`)
|
||||
|
||||
|
|
|
@ -120,6 +120,12 @@ interface ModelPeer {
|
|||
* @param count
|
||||
*/
|
||||
rowRemoved(row: number, count: number): void;
|
||||
|
||||
/**
|
||||
* Call this function from your own model to notify that the model has been
|
||||
* changed and everything must be reloaded
|
||||
*/
|
||||
reset(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -160,6 +166,7 @@ class NullPeer implements ModelPeer {
|
|||
rowDataChanged(row: number): void { }
|
||||
rowAdded(row: number, count: number): void { }
|
||||
rowRemoved(row: number, count: number): void { }
|
||||
reset(): void { }
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -142,6 +142,13 @@ declare_types! {
|
|||
}
|
||||
Ok(JsUndefined::new().as_value(&mut cx))
|
||||
}
|
||||
method reset(mut cx) {
|
||||
let this = cx.this();
|
||||
if let Some(model) = cx.borrow(&this, |x| x.0.upgrade()) {
|
||||
model.notify.reset()
|
||||
}
|
||||
Ok(JsUndefined::new().as_value(&mut cx))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue