wallace 0.2.0 → 0.3.0

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.
package/lib/component.js CHANGED
@@ -1,4 +1,4 @@
1
- const ALWAYS_UPDATE = "__";
1
+ const NO_LOOKUP = "__";
2
2
 
3
3
  /**
4
4
  * The base component.
@@ -52,7 +52,7 @@ proto._rq = function (props, key) {
52
52
  proto._ac = function (props, element, callbacks) {
53
53
  for (let key in callbacks) {
54
54
  let callback = callbacks[key];
55
- if (key === ALWAYS_UPDATE) {
55
+ if (key === NO_LOOKUP) {
56
56
  callback(element, props, this);
57
57
  } else {
58
58
  const result = this._rq(props, key);
package/lib/types.d.ts CHANGED
@@ -16,6 +16,7 @@
16
16
  6. Inheritance
17
17
  7. Stubs
18
18
  8. TypeScript
19
+ 9. Utility functions
19
20
 
20
21
  For more detailed documentation go to https://github.com/wallace-js/wallace
21
22
 
@@ -189,9 +190,11 @@ over it in your IDE.
189
190
 
190
191
  You can also display this list by hovering over any JSX element, like `div`.
191
192
 
193
+ - `apply` runs a callback to modify an element.
192
194
  - `bind` updates a value when an input is changed.
193
195
  - `class:xyz` defines a set of classes to be toggled.
194
- - `hide` sets and element or component's hidden property.
196
+ - `hide` sets an element or component's hidden property.
197
+ - `html` Set the element's `innnerHTML` property.
195
198
  - `if` excludes an element from the DOM.
196
199
  - `on[EventName]` creates an event handler (note the code is copied)
197
200
  - `props` specifes props for a nested or repeated component, in which case it must be
@@ -305,7 +308,7 @@ Notes:
305
308
 
306
309
  ## 8. TypeScript
307
310
 
308
- All typing comes from the `Uses` type which must be placed right after the comonent name:
311
+ The main type is `Uses` which must be placed right after the comonent name:
309
312
 
310
313
  ```tsx
311
314
  import { Uses } from 'wallace';
@@ -418,6 +421,43 @@ const Child = extendComponent<newProps, Controller, Methods>(Parent);
418
421
  to `any`.
419
422
  2. Each type must extend its corresponding type on base.
420
423
 
424
+ ### Other types:
425
+
426
+ Wallace defines some other types you may use:
427
+
428
+ - `Component<Props, Controller, Methods>` - the base component class (it is a
429
+ constructor, not a class)
430
+ - `ComponentInstance<Props, Controller, Methods>` - a component instance.
431
+
432
+ ## Utility functions
433
+
434
+ Each of these has their own JSDoc, we just lsit them here.
435
+
436
+
437
+ ### extendComponent
438
+
439
+ Define a new componend by extending another one:
440
+
441
+ ```
442
+ const Foo = extendComponent(Base);
443
+ const Bar = extendComponent(Base, () => <div></div>);
444
+ ```
445
+
446
+ ### mount
447
+
448
+ Mounts an instance of a component to the DOM:
449
+
450
+ ```
451
+ mount("elementId", MyComponent, props, ctrl);
452
+ ```
453
+
454
+ ### watch
455
+
456
+ Returns a Proxy of an object which calls `callback` when keys are set:
457
+
458
+ ```
459
+ watch(obj, () => console.log('obj modified);
460
+ ```
421
461
  ---
422
462
  Report any issues to https://github.com/wallace-js/wallace (and please give it a ★)
423
463
 
@@ -514,7 +554,7 @@ declare module "wallace" {
514
554
  /**
515
555
  * The component constructor function (typed as a class, but isn't).
516
556
  */
517
- export class Component__<Props = any, Controller = any> {
557
+ export class Component<Props = any, Controller = any> {
518
558
  update(): void;
519
559
  render(props: Props, ctrl?: Controller): void;
520
560
  }
@@ -566,15 +606,15 @@ declare module "wallace" {
566
606
  * The callback does not indicate the data has changed, only that a key was set.
567
607
  *
568
608
  * Some methods like `Array.push` set the index and then the length immediately after,
569
- * so we use a grace period to avoid calling the callback twice for what is really a
609
+ * so we use a timeout period to avoid calling the callback twice for what is really a
570
610
  * single operation.
571
611
  *
572
612
  * @param {*} target - Any object, including arrays.
573
- * @param {*} grace - Any value in ms. Defaults to 100.
613
+ * @param {*} timeout - Any value in ms. Defaults to 100.
574
614
  * @param {*} callback - A callback function.
575
615
  * @returns a Proxy of the object.
576
616
  */
577
- export function watch<T>(target: T, callback: CallableFunction, grace?: number): T;
617
+ export function watch<T>(target: T, callback: CallableFunction, timeout?: number): T;
578
618
  }
579
619
 
580
620
  type MustBeExpression = Exclude<any, string>;
@@ -585,14 +625,25 @@ type MustBeExpression = Exclude<any, string>;
585
625
  */
586
626
  interface DirectiveAttributes extends AllDomEvents {
587
627
  /**
588
- * ## Wallace directive: base
628
+ * ## Wallace directive: apply
629
+ *
630
+ * Applies a callback, typically to modify its element, which is accessible via
631
+ * **xargs**.
632
+ *
633
+ * Note that you can use `element` from **xargs** multiple times and each will refer
634
+ * to the element where it is used.
589
635
  *
590
- * Specifies a base component definition to inherit from.
636
+ * ```
637
+ * const MyComponent = (_, { element }) => (
638
+ * <div>
639
+ * <div apply={doSomething(element)}></div>
640
+ * <div apply={doSomethingElse(element)}></div>
641
+ * </div>
642
+ * );
643
+ * ```
591
644
  *
592
- * This allows you to inherit methods and override stubs.
593
- * Must be an expression returning a component definition.
594
645
  */
595
- base?: MustBeExpression;
646
+ apply?: MustBeExpression;
596
647
 
597
648
  /**
598
649
  * ## Wallace directive: bind
@@ -668,6 +719,12 @@ interface DirectiveAttributes extends AllDomEvents {
668
719
  */
669
720
  hide?: MustBeExpression;
670
721
 
722
+ /** ## Wallace directive: html
723
+ *
724
+ * Set the element's `innnerHTML` property.
725
+ */
726
+ html?: MustBeExpression;
727
+
671
728
  /** Wallace excludes this element from the DOM if the condition is false,
672
729
  * and does not render dynamic elements underneath. */
673
730
  if?: MustBeExpression;
@@ -750,11 +807,20 @@ declare namespace JSX {
750
807
 
751
808
  interface IntrinsicElements {
752
809
  /**
810
+ * Nesting syntax:
811
+ * ```
812
+ * <MyComponent.nest props={singleProps} />
813
+ * <MyComponent.repeat props={arrayOfProps} />
814
+ * ```
815
+ * But note that repeat must not have siblings.
816
+ *
753
817
  * Available Wallace directives:
754
818
  *
819
+ * - `apply` runs a callback to modify an element.
755
820
  * - `bind` updates a value when an input is changed.
756
821
  * - `class:xyz` defines a set of classes to be toggled.
757
- * - `hide` sets and element or component's hidden property.
822
+ * - `hide` sets an element or component's hidden property.
823
+ * - `html` Set the element's `innnerHTML` property.
758
824
  * - `if` excludes an element from the DOM.
759
825
  * - `on[EventName]` creates an event handler (note the code is copied)
760
826
  * - `props` specifes props for a nested or repeated component, in which case it must be
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wallace",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "author": "Andrew Buchan",
5
5
  "description": "The framework that brings you FREEDOM!!",
6
6
  "license": "ISC",
@@ -13,8 +13,8 @@
13
13
  "test": "jest --clearCache && jest"
14
14
  },
15
15
  "dependencies": {
16
- "babel-plugin-wallace": "^0.2.0",
16
+ "babel-plugin-wallace": "^0.3.0",
17
17
  "browserify": "^17.0.1"
18
18
  },
19
- "gitHead": "fb51a4f90bd819a79515196b0fd57d36fa7d6477"
19
+ "gitHead": "d5f2ea2912b6ec729775d2ccf17973a9e791115f"
20
20
  }