bcherny / bcherny/ngimport

Module.run() will never be run unless that module is included/required in your AngularJS app

Open
#14 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
100
Forks
5
PR merge metrics
No merged PRs in 30d

Description

In your section "Using this technique to wrap your own legacy modules" you make it seem as if `module('myModule').run` is going to be executed with just the code that is shown but that's not the case in my experience. Your `myModule` must be bootstrapped in order for that run method to be executed. So this means it must be bootstrapped directly or added as a [requires](https://docs.angularjs.org/api/ng/function/angular.module#angular.module-arguments#angular.module-arguments) of another module. Whether that be your top-level angular module that's being bootstrapped or one of that module's `required` downstream modules.

Example: If I were going to do this to import a contract-service in a react component somewhere in my page, I'd need to go find an angularjs module which will be bootstrapped and tack on contract service as a dependency. Once done, the `run` function will get executed on the module and it'll expose my contract-service appropriately.

```
import ContractService from '../../contract-service.js';

var angular = require('angular');

module.exports = angular.module('a.module.which.will.be.bootstrapped', [
ContractService
])
```

This unfortunately reduces the flexibility of this technique.
* You can't for instance NPM install a bunch of your AngularJS services and use them in a ReactJS app that isn't bootstrapping any angular.
* You have to have a higher up angularjs module add/require all of the potential modules in which you may at some point want to import using this technique. This seems bad to me as you're either going to include a bunch of modules that may never even be used. Or you'll have to maintain a list of requirements in an angularjs module and include each thing you wish to use in your reactjs code. It just feels messy.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the “Using this technique to wrap your own legacy modules” section mentioned in the issue and verify its claims against the AngularJS module.run and dependency documentation linked in the report. Update the section so its module bootstrapping requirement and limitations are explicit; it is done when the example no longer implies that an unrequired module will run independently.

Written by the indexing model from the issue text.

Assessment

Tech stack
angularjs, react
Domain
documentation, frontend
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.