MCPcopy Create free account
hub / github.com/neomjs/neo / beforeSetInstance

Method beforeSetInstance

src/util/ClassSystem.mjs:23–61  ·  view source on GitHub ↗

* can get used inside beforeSet methods in case you want to create instances like stores * @param {Object|Neo.core.Base|null} config * @param {Neo.core.Base|String} [DefaultClass=null] * @param {Object} [defaultValues={}] * @returns {Neo.core.Base} instance

(config, DefaultClass=null, defaultValues={})

Source from the content-addressed store, hash-verified

21 * @returns {Neo.core.Base} instance
22 */
23 static beforeSetInstance(config, DefaultClass=null, defaultValues={}) {
24 let configType = Neo.typeOf(config);
25
26 if (Neo.isString(DefaultClass)) {
27 DefaultClass = Neo.ns(DefaultClass)
28 }
29
30 if (!config && DefaultClass) {
31 config = Neo.create(DefaultClass, defaultValues)
32 } else if (configType === 'NeoClass') {
33 config = Neo.create(config, defaultValues)
34 } else if (configType === 'Object') {
35 if (config.ntype) {
36 config = Neo.ntype({
37 ...defaultValues,
38 ...config
39 })
40 } else {
41 let newConfig = {};
42
43 if (DefaultClass) {
44 newConfig.module = DefaultClass
45 }
46
47 Object.assign(newConfig, {
48 ...defaultValues,
49 ...config
50 });
51
52 config = Neo.create(newConfig)
53 }
54 } else if (configType === 'NeoInstance') {
55 if (defaultValues?.listeners) {
56 config.on(defaultValues.listeners)
57 }
58 }
59
60 return config
61 }
62}
63
64export default Neo.setupClass(ClassSystem);

Callers 15

beforeSetEdgesMethod · 0.80
beforeSetNodesMethod · 0.80
beforeSetStorageMethod · 0.80
beforeSetAssemblerMethod · 0.80
beforeSetProviderMethod · 0.80
beforeSetStoreMethod · 0.80
beforeSetStoreMethod · 0.80
beforeSetMainViewMethod · 0.80
beforeSetStoreMethod · 0.80

Calls 3

isStringMethod · 0.80
onMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected