overrides.js

  1. export var array_overrides = {};
  2. export var operation_overrides = {};
  3. function registerHandler(key, handler, overrides) {
  4. if (key in overrides) {
  5. let old = overrides[key];
  6. if (handler == null){
  7. delete overrides[key];
  8. } else {
  9. overrides[key] = handler;
  10. }
  11. return old;
  12. }
  13. if (handler !== null) {
  14. overrides[key] = handler;
  15. }
  16. return null;
  17. }
  18. /**
  19. * Get or set custom handlers for arrays in a **chihaya**-formatted HDF5 file.
  20. *
  21. * @param {string} array - Type of the delayed array, matched against the `delayed_array` attribute.
  22. * @param {?function} handler - Handler function that accepts a HDF5 group handle (corresponding to the array) and returns a {@linkplain external:ScranMatrix ScranMatrix} object.
  23. * Handlers may be async.
  24. * If `null`, any custom handler was previously registered will be removed.
  25. *
  26. * @return {?function} The previously registered handler function, or `null` if no handler was previously registered.
  27. */
  28. export function registerArrayHandler(array, handler) {
  29. return registerHandler(array, handler, array_overrides);
  30. }
  31. /**
  32. * Get or set custom handlers for delayed operations in a **chihaya**-formatted HDF5 file.
  33. *
  34. * @param {string} operation - Type of the delayed operation, matched against the `delayed_operation` attribute.
  35. * @param {?function} handler - Handler function that accepts a HDF5 group handle (corresponding to the delayed operation) and returns a {@linkplain external:ScranMatrix ScranMatrix} object.
  36. * Handlers may be async.
  37. * If `null`, any custom handler was previously registered will be removed.
  38. *
  39. * @return {?function} The previously registered handler function, or `null` if no handler was previously registered.
  40. */
  41. export function registerOperationHandler(operation, handler) {
  42. return registerHandler(operation, handler, operation_overrides);
  43. }