Skip to content

Commit

Permalink
feat(ModuleConfig): Move defaultViewArgs to a module setting
Browse files Browse the repository at this point in the history
  • Loading branch information
elpete committed Jan 29, 2020
1 parent aca6acd commit f55f374
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
4 changes: 4 additions & 0 deletions ModuleConfig.cfc
Expand Up @@ -11,6 +11,10 @@ component {
"autoRegisterInterceptor": true,
"autoRegisterHelpers": true,
"autoRegisterControllerDecorator": true,
"defaultViewArgs": {
"view": "main/index",
"module": "cbInertia"
},
"version": function() {
return "";
}
Expand Down
28 changes: 26 additions & 2 deletions README.md
Expand Up @@ -30,8 +30,12 @@ box install cbInertia
```

By default, no configuration is needed. However, you can disable the automatic
registering of the `InertiaLifecycle` interceptor and/or the cbInertia application
helpers, if you wish.
registering of the `InertiaLifecycle` interceptor, the cbInertia application
helper, or the Controller decorator if you wish. You can also customize the
view arguments for Inertia events.

The one setting you will likely modify is the `version` setting. You can read
more about it below.

```
// config/ColdBox.cfc
Expand All @@ -40,6 +44,10 @@ moduleSettings = {
"autoRegisterInterceptor": true,
"autoRegisterHelpers": true,
"autoRegisterControllerDecorator": true,
"defaultViewArgs": {
"view": "main/index",
"module": "cbInertia"
}
"version": function() {
return "";
}
Expand Down Expand Up @@ -133,6 +141,22 @@ inertia.share( "user", function() {

You can call `share` as many times as you need.

### Customizing the Inertia View

The default view that ships with cbInertia suits most use cases. If you need
to use a different view for any reason, you can customize the view arguments
sent to the `setView` function using the `defaultViewArgs` setting.

```cfc
moduleSettings = {
"cbInertia": {
"defaultViewArgs": {
"view": "custom/view/page"
}
}
};
```

### Controller Decorator

Inertia automatically registers a Controller decorator by default. This
Expand Down
5 changes: 1 addition & 4 deletions interceptors/InertiaLifecycle.cfc
@@ -1,10 +1,7 @@
component {

property name="version" inject="coldbox:setting:version@cbInertia";

function configure() {
variables.defaultViewArgs = { "view": "main/index", "module": "cbInertia" };
}
property name="defaultViewArgs" inject="coldbox:setting:defaultViewArgs@cbInertia";

function preProcess( event ) {
if ( event.getHTTPHeader( "X-Inertia", "" ) == "" ) {
Expand Down

0 comments on commit f55f374

Please sign in to comment.