native_object.km 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. type Object
  2. native; // qt.Object
  3. type Static [out Obj]
  4. opaque
  5. Obj;
  6. type PropType
  7. protected
  8. String;
  9. const PropTypeString: PropType :=
  10. 'String'.{|PropType|};
  11. const PropTypeBool: PropType :=
  12. 'Bool'.{|PropType|};
  13. const PropTypeMaybeNumber: PropType :=
  14. 'MaybeNumber'.{|PropType|};
  15. function get-property: [Obj < Object, T]
  16. &(Static[Obj], String, PropType) => T
  17. native 'qt-get-property';
  18. function set-property: [T]
  19. &(Object, String, PropType, T) => Async
  20. native 'qt-set-property';
  21. function bind-property: [T]
  22. & { object: Object,
  23. prop: String,
  24. type: PropType,
  25. source: Source[T] }
  26. => Async[never]
  27. & { object, prop, type, source } =>
  28. (source connect &(value) => {
  29. set-property (object, prop, type, value) });
  30. function bind-property: [T]
  31. & { object: Object,
  32. prop: String,
  33. type: PropType,
  34. notify: String,
  35. sync: Reactive[T] }
  36. => Async[never]
  37. & { object, prop, type, notify, sync } =>
  38. let write :=
  39. let source := { watch sync },
  40. { bind-property { object, prop, type, source } },
  41. let read :=
  42. let source := { Signal (object, notify, &(object) => {
  43. get-property (object, prop, type) }.[T]) },
  44. (source connect sync),
  45. { merge [read, write] };