Skip to content

Commit 01dc206

Browse files
committed
Add option system to allow to selectively enable options
1 parent 6d1bace commit 01dc206

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

react_ujs/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var constructorFromRequireContext = require("./src/getConstructor/fromRequireCon
88
var constructorFromRequireContextWithGlobalFallback = require("./src/getConstructor/fromRequireContextWithGlobalFallback")
99
var constructorFromRequireContextsWithGlobalFallback = require("./src/getConstructor/fromRequireContextsWithGlobalFallback")
1010
const { supportsHydration, reactHydrate, createReactRootLike } = require("./src/renderHelpers")
11-
const { replaceNullWithUndefined } = require("./src/options")
11+
const { replaceNullWithUndefined, overwriteOption } = require("./src/options")
1212

1313
var ReactRailsUJS = {
1414
// This attribute holds the name of component which should be mounted
@@ -37,6 +37,10 @@ var ReactRailsUJS = {
3737
replaceNull: false,
3838
},
3939

40+
setOptions: function(newOptions) {
41+
overwriteOption(ReactRailsUJS.options, newOptions, "replaceNull")
42+
},
43+
4044
// helper method for the mount and unmount methods to find the
4145
// `data-react-class` DOM elements
4246
findDOMNodes: function(searchSelector) {

react_ujs/src/options.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ export function replaceNullWithUndefined(obj) {
1111
})
1212
return obj
1313
}
14+
15+
export function overwriteOption(ujsOptions, newOptions, key) {
16+
if (!Object.prototype.hasOwnProperty.call(newOptions, key)) return
17+
ujsOptions[key] = newOptions[key]
18+
}

0 commit comments

Comments
 (0)