Skip to content

Can almond be forced to require synchronously? #123

@ca0v

Description

@ca0v

I am wanting to develop modular service workers and I would like to continue using typescript and AMD modules to do it:

declare var requirejs: Function;
self.importScripts("../static/almond.js");
requirejs(["serviceworker/index"], (worker: { run: (worker:any) => void }) => worker.run(self));

The above results in the following error:

Event handler of 'fetch' event must be added on the initial evaluation of worker script.

The problem, I think, is the setTimout in following code in almond.js:

        //Simulate async callback;
        if (forceSync) {
            main(undef, deps, callback, relName);
        } else {
            setTimeout(function () {
                main(undef, deps, callback, relName);
            }, 4);
        }

I tried forcing forceSync to be true but ran into other problems. All the modules are in one concatenated filed thanks to the typescript compilers "outfile" option. Any guidence of possible code changes to allow almond to be used as a service worker loader?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions