neo.mjs 4.0.65 → 4.0.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,6 +36,7 @@ program
36
36
  .version(packageJson.version)
37
37
  .option('-i, --info', 'print environment debug info')
38
38
  .option('-d, --drop', 'drops class in the currently selected folder')
39
+ .option('-n, --singleton <value>', 'Create a singleton? Pick "yes" or "no"')
39
40
  .option('-s, --source <value>', `name of the folder containing the project. Defaults to any of ${sourceRootDirs.join(',')}`)
40
41
  .option('-b, --baseClass <value>')
41
42
  .option('-c, --className <value>')
@@ -117,11 +118,23 @@ if (programOpts.info) {
117
118
  });
118
119
  }
119
120
 
121
+ if (!programOpts.singleton) {
122
+ questions.push({
123
+ type : 'list',
124
+ name : 'singleton',
125
+ message: 'Singleton?',
126
+ default: 'no',
127
+ choices: ['yes', 'no']
128
+ });
129
+ }
130
+
120
131
  inquirer.prompt(questions).then(answers => {
121
- let baseClass = programOpts.baseClass || answers.baseClass,
122
- className = programOpts.className || answers.className,
123
- isDrop = programOpts.drop,
124
- startDate = new Date(),
132
+ let baseClass = programOpts.baseClass || answers.baseClass,
133
+ className = programOpts.className || answers.className,
134
+ singleton = programOpts.singleton || answers.singleton || 'no',
135
+ isDrop = programOpts.drop,
136
+ isSingleton = singleton === 'yes',
137
+ startDate = new Date(),
125
138
  baseFileName, baseType, classFolder, configName, file, folderDelta, importName, importPath, index, ns, root, rootLowerCase, viewFile;
126
139
 
127
140
  if (className.endsWith('.mjs')) {
@@ -214,12 +227,11 @@ if (programOpts.info) {
214
227
  baseFileName = baseFileName.map(e => capitalize(e)).join('');
215
228
  }
216
229
 
217
- console.log(baseFileName, baseClass);
218
-
219
230
  fs.writeFileSync(path.join(classFolder, file + '.mjs'), createContent({
220
231
  baseClass,
221
232
  baseFileName,
222
233
  className,
234
+ isSingleton,
223
235
  file,
224
236
  folderDelta,
225
237
  ns,
@@ -477,6 +489,7 @@ if (programOpts.info) {
477
489
  * @param {String} opts.baseClass
478
490
  * @param {String} opts.baseFileName
479
491
  * @param {String} opts.className
492
+ * @param {Boolean} opts.isSingleton
480
493
  * @param {String} opts.file
481
494
  * @param {String} opts.folderDelta
482
495
  * @param {String} opts.ns
@@ -488,6 +501,7 @@ if (programOpts.info) {
488
501
  baseFileName = opts.baseFileName,
489
502
  baseClassPath = baseClass.split('.').join('/'),
490
503
  className = opts.className,
504
+ isSingleton = opts.isSingleton,
491
505
  file = opts.file,
492
506
  i = 0,
493
507
  importDelta = '';
@@ -501,7 +515,14 @@ if (programOpts.info) {
501
515
  "",
502
516
  "/**",
503
517
  ` * @class ${className}`,
504
- ` * @extends Neo.${baseClass}`,
518
+ ` * @extends Neo.${baseClass}`
519
+ ];
520
+
521
+ isSingleton && classContent.push(
522
+ " * @singleton"
523
+ );
524
+
525
+ classContent.push(
505
526
  " */",
506
527
  `class ${file} extends ${baseFileName} {`,
507
528
  " static getConfig() {return {",
@@ -510,7 +531,7 @@ if (programOpts.info) {
510
531
  " * @protected",
511
532
  " */",
512
533
  ` className: '${className}'`
513
- ];
534
+ );
514
535
 
515
536
  baseClass === 'data.Model' && addComma(classContent).push(
516
537
  " /*",
@@ -529,6 +550,14 @@ if (programOpts.info) {
529
550
  " items: []"
530
551
  );
531
552
 
553
+ isSingleton && addComma(classContent).push(
554
+ " /*",
555
+ " * @member {Boolean} singleton=true",
556
+ " * @protected",
557
+ " */",
558
+ " singleton: true"
559
+ );
560
+
532
561
  baseClass === 'component.Base' && addComma(classContent).push(
533
562
  " /*",
534
563
  " * @member {Object} _vdom",
@@ -542,8 +571,22 @@ if (programOpts.info) {
542
571
  "}",
543
572
  "",
544
573
  `Neo.applyClassConfig(${file});`,
574
+ ""
575
+ );
576
+
577
+ isSingleton && classContent.push(
578
+ `let instance = Neo.create(${file});`,
545
579
  "",
546
- `export default ${file};`,
580
+ "Neo.applyToGlobalNs(instance);",
581
+ "",
582
+ "export default instance;"
583
+ );
584
+
585
+ !isSingleton && classContent.push(
586
+ `export default ${file};`
587
+ );
588
+
589
+ classContent.push(
547
590
  ""
548
591
  );
549
592
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo.mjs",
3
- "version": "4.0.65",
3
+ "version": "4.0.66",
4
4
  "description": "The webworkers driven UI framework",
5
5
  "type": "module",
6
6
  "repository": {
@@ -463,24 +463,8 @@ class Select extends Picker {
463
463
  * @protected
464
464
  */
465
465
  onListItemClick(record) {
466
- let me = this,
467
- displayField = me.displayField,
468
- oldValue = me.value,
469
- value = record[displayField];
470
-
471
- if (me.value !== value) {
472
- me.hintRecordId = null;
473
- me.record = record;
474
- me._value = value;
475
- me.getInputHintEl().value = null;
476
-
477
- me.afterSetValue(value, oldValue, true); // prevent the list from getting filtered
478
-
479
- me.fire('select', {
480
- record,
481
- value: record[displayField]
482
- });
483
- }
466
+ this.onListItemChange(record);
467
+ this.hidePicker();
484
468
  }
485
469
 
486
470
  /**
@@ -518,12 +502,38 @@ class Select extends Picker {
518
502
  this.focusInputEl();
519
503
  }
520
504
 
505
+
506
+ /**
507
+ * @param {Object} record
508
+ * @protected
509
+ */
510
+ onListItemChange(record) {
511
+ let me = this,
512
+ displayField = me.displayField,
513
+ oldValue = me.value,
514
+ value = record[displayField];
515
+
516
+ if (me.value !== value) {
517
+ me.hintRecordId = null;
518
+ me.record = record;
519
+ me._value = value;
520
+ me.getInputHintEl().value = null;
521
+
522
+ me.afterSetValue(value, oldValue, true); // prevent the list from getting filtered
523
+
524
+ me.fire('select', {
525
+ record,
526
+ value: record[displayField]
527
+ });
528
+ }
529
+ }
530
+
521
531
  /**
522
532
  * @param {Object} record
523
533
  * @protected
524
534
  */
525
535
  onListItemNavigate(record) {
526
- this.onListItemClick(record);
536
+ this.onListItemChange(record);
527
537
  }
528
538
 
529
539
  /**