Skip to content
This repository was archived by the owner on Nov 21, 2025. It is now read-only.

Conversation

@Shepless
Copy link
Contributor

@Shepless Shepless commented Aug 1, 2014

This PR allows users to specify which module a constant should be attached to, using the following syntax:

window.deferredBootstrapper.bootstrap({
        element: document.body,
        module: 'MainApp',
        moduleResolves: [
            {
                module: 'MainApp.Constants',
                resolve: {
                    CONSTANT_ONE: ['$http', function ($http) {
                        return $http.get();
                    }],
                    CONSTANT_TWO: ['$http', function ($http) {
                        return $http.get();
                    }]
                }
            },
            {
                module: 'MainApp.MoreConstants',
                resolve: {
                    ANOTHER_CONSTANT: ['$http', function ($http) {
                        return $http.get();
                    }]
                }
            }
        ]
    })

In the example above, CONTANT_ONE and CONSTANT_TWO will be added to the MainApp.Constants module and ANOTHER_CONSTANT will be added to the MainApp.MoreConstants module. Notice above that x amount of constants can be added to a module, the user is not limited in this respect.

To minimise impact I have re-used the exact same approach to calling the resolve functions but wrapped in additional forEach loops.

For simplicity a user can only specify either the standard resolve OR the moduleResolves options. The following would throw an exception whilst checking the config:

window.deferredBootstrapper.bootstrap({
        element: document.body,
        module: 'MainApp',
       resolve: {
            FOO: ['$http', function ($http) {
                        return $http.get();
                    }]
       },
        moduleResolves: [
            {
                module: 'MainApp.Constants',
                resolve: {
                    CONSTANT_ONE: ['$http', function ($http) {
                        return $http.get();
                    }]
                }
            }
        ]
    })

I've added a few unit tests for config checking and also to ensure constants get added to the correct modules.

Let me know if this meets the requirements, if not I'll go back to the drawing board.

Cheers

@Shepless
Copy link
Contributor Author

Shepless commented Aug 1, 2014

The build is failing when pulling in bower dependencies, which hasn't changed at all so not sure what is going on here. Travis config might need looking at?

@philippd
Copy link
Owner

philippd commented Aug 2, 2014

Thanks for the PR, looks like a nice feature and i'll have a closer look tomorrow. If you have the time it would be great if you could update the readme and document this feature. thanks!

Shepless and others added 2 commits August 2, 2014 13:47
Added documentation for the moduleResolves config option
@Shepless
Copy link
Contributor Author

Shepless commented Aug 2, 2014

@philippd Updated the README and added a new demo. I'm not the best at documentation so feel free to modify it.

philippd added a commit that referenced this pull request Aug 3, 2014
Added ability to specify which module a constant is added to
@philippd philippd merged commit a012373 into philippd:master Aug 3, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants