Add a reset function to the model notifier

This commit is contained in:
Olivier Goffart 2022-04-14 14:06:34 +02:00 committed by GitHub
parent 2b93504b93
commit f5030cff06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 4 deletions

View file

@ -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`)

View file

@ -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 { }
}
/**

View file

@ -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))
}
}