FLUID-6752: Arguments to listeners are expanded eagerly, inconsistent with strategy for invoker arguments

Metadata

Source
FLUID-6752
Type
Bug
Priority
Major
Status
Open
Resolution
N/A
Assignee
Antranig Basman
Reporter
Antranig Basman
Created
2022-10-14T09:57:37.676-0400
Updated
2024-07-17T08:02:21.964-0400
Versions
  1. 4.4
Fixed Versions
  1. 6.0
Component
  1. Framework

Description

Arguments to listeners are expanded by a custom workflow leading from fluid.instantiateEvents -> fluid.mergeListeners -> fluid.event.resolveListenerRecord using the old-fashioned heavyweight "fluid.expandOptions"" rather than the more modern "fluid.preExpandOptions" seen in fluid.makeInvoker:

fluid.event.resolveListenerRecord = function (lisrec, that, eventName, namespace, standard) {
....
    var transRecs = fluid.transform(records, function (record) {
.... 
        var listener = expanded.listener = fluid.expandOptions(expanded.listener, that);

This implies that any volatile references, e.g. to model material will likely cause a workflow failure. We encountered this when writing a dataSource transforming event listener as

"onRead.impl": {
            func: "hortis.sqliteSource.read",
            args: ["{that}.model.db", "{that}.options.readQuery", "{arguments}.0"]
        },

which ended up forcing model evaluation far too early, as part of the pseudo-workflow stage 0 attached to "fluid.instantiateEvents" in the transitional framework.

What will this look like in the future? Probably not vastly different - we will still likely have some kind of monomorphisation site attached to these resolution sites, only we will at least have somewhere sensible to cache their results as part of the immutable tree. There will still be "workflow stages" only these will be scheduled as ticks rather than as promise tangles.

Analogous issues are FLUID-6373, noting that the "func" member of listeners/invokers is always evaluated early, and FLUID-6405 noting that the evaluation of "listener" members of IoC testing framework blocks is always eager.