* Use Neo.create() instead of "new" to create instances of all Neo classes * @example * import Button from '../button/Base.mjs'; * * Neo.create(Button, { * iconCls: 'fa fa-home', * text : 'Home' * }); * @example * import Button from '../button/B
(className, config)
| 290 | * @returns {Neo.core.Base|null} The new class instance |
| 291 | */ |
| 292 | create(className, config) { |
| 293 | let type = Neo.typeOf(className), |
| 294 | cls, instance; |
| 295 | |
| 296 | if (type === 'NeoClass') { |
| 297 | cls = className |
| 298 | } else { |
| 299 | if (type === 'Object') { |
| 300 | config = className; |
| 301 | |
| 302 | if (!config.className && !config.module) { |
| 303 | // using console.error instead of throw to show the config object |
| 304 | console.error('Class created with object configuration missing className or module property', config); |
| 305 | return null |
| 306 | } |
| 307 | |
| 308 | className = config.className || config.module.prototype.className |
| 309 | } |
| 310 | |
| 311 | if (!exists(className)) { |
| 312 | throw new Error('Class ' + className + ' does not exist') |
| 313 | } |
| 314 | |
| 315 | cls = Neo.ns(className) |
| 316 | } |
| 317 | |
| 318 | instance = new cls(); |
| 319 | |
| 320 | instance.construct(config); |
| 321 | instance.onConstructed(); |
| 322 | instance.onAfterConstructed(); |
| 323 | instance.init(); |
| 324 | |
| 325 | return instance |
| 326 | }, |
| 327 | |
| 328 | /** |
| 329 | * Defines a reactive configuration property on a target object (prototype or instance). |
nothing calls this directly
no test coverage detected