@b9g/crank 0.4.4 → 0.5.0-beta.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/crank.d.ts CHANGED
@@ -166,9 +166,9 @@ export declare function isElement(value: any): value is Element;
166
166
  * children prop according to any additional arguments passed to the function.
167
167
  */
168
168
  export declare function createElement<TTag extends Tag>(tag: TTag, props?: TagProps<TTag> | null | undefined, ...children: Array<unknown>): Element<TTag>;
169
- /**
170
- * Clones a given element, shallowly copying the props object.
171
- */
169
+ /** A single-letter alias for createElement */
170
+ export declare const c: typeof createElement;
171
+ /** Clones a given element, shallowly copying the props object. */
172
172
  export declare function cloneElement<TTag extends Tag>(el: Element<TTag>): Element<TTag>;
173
173
  /**
174
174
  * A helper type which repesents all possible rendered values of an element.
package/crank.js CHANGED
@@ -105,6 +105,7 @@ class Element {
105
105
  this.static_ = static_;
106
106
  }
107
107
  }
108
+ // See Element interface
108
109
  Element.prototype.$$typeof = ElementSymbol;
109
110
  function isElement(value) {
110
111
  return value != null && value.$$typeof === ElementSymbol;
@@ -127,6 +128,7 @@ function createElement(tag, props, ...children) {
127
128
  switch (name) {
128
129
  case "crank-key":
129
130
  case "c-key":
131
+ case "$key":
130
132
  // We have to make sure we don’t assign null to the key because we
131
133
  // don’t check for null keys in the diffing functions.
132
134
  if (props[name] != null) {
@@ -135,12 +137,14 @@ function createElement(tag, props, ...children) {
135
137
  break;
136
138
  case "crank-ref":
137
139
  case "c-ref":
140
+ case "$ref":
138
141
  if (typeof props[name] === "function") {
139
142
  ref = props[name];
140
143
  }
141
144
  break;
142
145
  case "crank-static":
143
146
  case "c-static":
147
+ case "$static":
144
148
  static_ = !!props[name];
145
149
  break;
146
150
  default:
@@ -154,11 +158,27 @@ function createElement(tag, props, ...children) {
154
158
  else if (children.length === 1) {
155
159
  props1.children = children[0];
156
160
  }
161
+ // string aliases for the special tags
162
+ // TODO: Does this logic belong here, or in the Element constructor
163
+ switch (tag) {
164
+ case "$FRAGMENT":
165
+ tag = Fragment;
166
+ break;
167
+ case "$PORTAL":
168
+ tag = Portal;
169
+ break;
170
+ case "$COPY":
171
+ tag = Copy;
172
+ break;
173
+ case "$RAW":
174
+ tag = Raw;
175
+ break;
176
+ }
157
177
  return new Element(tag, props1, key, ref, static_);
158
178
  }
159
- /**
160
- * Clones a given element, shallowly copying the props object.
161
- */
179
+ /** A single-letter alias for createElement */
180
+ const c = createElement;
181
+ /** Clones a given element, shallowly copying the props object. */
162
182
  function cloneElement(el) {
163
183
  if (!isElement(el)) {
164
184
  throw new TypeError("Cannot clone non-element");
@@ -732,9 +752,9 @@ const IsDone = 1 << 4;
732
752
  *
733
753
  * NOTE: This is mainly used to prevent some false positives in component
734
754
  * yields or returns undefined warnings. The reason we’re using this versus
735
- * IsUnmounted is a very troubling jest test (cascades sync generator parent
736
- * and sync generator child) where synchronous code causes a stack overflow
737
- * error in a non-deterministic way. Deeply disturbing stuff.
755
+ * IsUnmounted is a very troubling test (cascades sync generator parent and
756
+ * sync generator child) where synchronous code causes a stack overflow error
757
+ * in a non-deterministic way. Deeply disturbing stuff.
738
758
  */
739
759
  const IsErrored = 1 << 5;
740
760
  /**
@@ -1635,5 +1655,5 @@ function propagateError(ctx, err) {
1635
1655
  // default export. Prefer named exports when importing directly.
1636
1656
  var crank = { createElement, Fragment };
1637
1657
 
1638
- export { Context, Copy, Element, Fragment, Portal, Raw, Renderer, cloneElement, createElement, crank as default, isElement };
1658
+ export { Context, Copy, Element, Fragment, Portal, Raw, Renderer, c, cloneElement, createElement, crank as default, isElement };
1639
1659
  //# sourceMappingURL=crank.js.map