Skip to content

Commit

Permalink
feat(ModuleConfig): Add toggles for automatic registering of intercep…
Browse files Browse the repository at this point in the history
…tors and helpers

You can now turn off the automatic registering of interceptors and helpers with the
following two settings: `autoRegisterInterceptor` and `autoRegisterHelpers`
  • Loading branch information
elpete committed Dec 31, 2019
1 parent 5bb6feb commit 7ccb0f9
Showing 1 changed file with 35 additions and 13 deletions.
48 changes: 35 additions & 13 deletions ModuleConfig.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,49 @@ component {
this.dependencies = [ "vue-helpers" ];

function configure() {
settings = {
"autoRegisterInterceptor": true,
"autoRegisterHelpers": true
};

interceptors = [
{ class = "#moduleMapping#.interceptors.InertiaLifecycle" }
{ "class": "#moduleMapping#.interceptors.InertiaLifecycle" }
];
}

function onLoad() {
var helpers = controller.getSetting( "applicationHelper" );
arrayAppend(
helpers,
"#moduleMapping#/helpers/Inertia.cfm"
);
controller.setSetting( "applicationHelper", helpers );
if ( settings.autoRegisterInterceptor ) {
controller.getInterceptorService().registerInterceptor(
interceptorName = "InertiaLifecycleInterceptor",
interceptorClass = "#moduleMapping#.interceptors.InertiaLifecycle"
);
}

if ( settings.autoRegisterHelpers ) {
var helpers = controller.getSetting( "applicationHelper" );
arrayAppend(
helpers,
"#moduleMapping#/helpers/Inertia.cfm"
);
controller.setSetting( "applicationHelper", helpers );
}
}

function onUnload() {
controller.setSetting(
"applicationHelper",
arrayFilter( controller.getSetting( "applicationHelper" ), function( helper ) {
return helper != "#moduleMapping#/helpers/Inertia.cfm";
} )
);
if ( settings.autoRegisterHelpers ) {
controller.setSetting(
"applicationHelper",
arrayFilter( controller.getSetting( "applicationHelper" ), function( helper ) {
return helper != "#moduleMapping#/helpers/Inertia.cfm";
} )
);
}

if ( settings.autoRegisterInterceptor ) {
controller.getInterceptorService().unregister(
interceptorName = "InertiaLifecycleInterceptor"
);
}
}

}

0 comments on commit 7ccb0f9

Please sign in to comment.