Factor 'sandbox.on' and 'sandbox.once' with a single 'attachListener' function