mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 22:31:14 +00:00
ArrayModel support in JS
This commit is contained in:
parent
c9e5e5f25b
commit
14198052ac
9 changed files with 320 additions and 33 deletions
|
@ -18,7 +18,7 @@ function load_native_lib() {
|
|||
return module.exports;
|
||||
}
|
||||
|
||||
const native = !process.env.SIXTYFPS_NODE_NATIVE_LIB ? require('../native/index.node') : load_native_lib();
|
||||
let native = !process.env.SIXTYFPS_NODE_NATIVE_LIB ? require('../native/index.node') : load_native_lib();
|
||||
|
||||
require.extensions['.60'] =
|
||||
function (module, filename) {
|
||||
|
@ -47,4 +47,23 @@ require.extensions['.60'] =
|
|||
}
|
||||
}
|
||||
|
||||
native.ArrayModel = function (arr) {
|
||||
let a = arr || [];
|
||||
return {
|
||||
row_count() { return a.length; },
|
||||
row_data(row) { return a[row]; },
|
||||
set_row_data(row, data) { a[row] = data; this.notify.row_data_changed(row); },
|
||||
push() {
|
||||
let size = a.length;
|
||||
Array.prototype.push.apply(a, arguments);
|
||||
this.notify.row_added(size, arguments.length);
|
||||
},
|
||||
// FIXME: should this be named splice and hav ethe splice api?
|
||||
remove(index, size) {
|
||||
let r = a.splice(index, size);
|
||||
this.notify.row_removed(size, arguments.length);
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = native;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue