@edular/modules
v3.9.0
Published
![current npm version](https://img.shields.io/npm/v/@edular/modules?label=%40edular%2Fmodules)
Downloads
331
Readme
@edular/modules
Shared constants and utils for modules handling in Edular
project.
How to use the library
yarn add @edular/modules
or
npm install --save @edular/modules
Initialize
Wrap your parent component with EdularModulesProvider
//App.tsx
import { EdularModulesProvider } from '@edular/modules';
// ...
return (
<EdularModulesProvider>
<ChildComponent />
</EdularModulesProvider>
);
Somewhere in the app when you have profile and token ready
import { useEdularModuleContext } from '@edular/modules';
function OtherComponent() {
const profile = useSelector(getActiveProfileState);
const {
initialize, // Initialize modules
refreshModules, // Use this in case you need to refresh modules
} = useEdularModuleContext();
useEffect(() => {
if (!profile) {
return;
}
initialize({
profileId: profile.id,
token: keychain.getTokens().accessToken,
baseUrl: config.edularApiBaseUrl,
});
}, [profile]);
// In mobile, I would like to refresh module whenever app is bring back to foreground
useAppState(state => {
if (state === 'active') {
refreshModules();
}
});
}
Usage
In functional component
import { useEdularModuleContext, Modules } from '@edular/modules';
function SomeComponent() {
const { isModuleEnable } = useEdularModuleContext();
return (
<Component>
{isModuleEnable(Modules.Admissions) && <AdmissionsComponent />}
</Component>
);
}
In class component
import { EdularModulesContext, Modules } from '@edular/modules';
class SomeComponent() {
static contextType = EdularModulesContext
render() {
const { isModuleEnable} = this.context
return (
<Component>
{isModuleEnable(Modules.Admissions) && <AdmissionsComponent />}
</Component>
)
}
}
Modules
The repository contains the modules.ts
file that exports Modules
object — all available modules.
The file is generated based on the modules list from the main Edular database.
Scripts
build
— building the library artifacts (lib/
directory)build:clean
— clean the build directorylib/
generate-modules
— generatemodules.ts
with theModules
object exported
How to publish new version
- Start the edular-core and run
yarn generate-modules
to generate newmodules.ts
. - Commit the change and run
npm version major|minor|patch -m "bump %s"
to bump new version. - Publish to npm registry by running
yarn publish
. - Update the
version
inpackage.json
manually or usenpm
for that:
npm version <major|minor|patch>
Commit the changes and push them to the remote repository
Publish new version to npm registry
npm publish