omis - build

This commit is contained in:
dntzhang 2019-07-23 15:03:40 +08:00
parent 680cf803e2
commit 1024007e9f
17 changed files with 108 additions and 177 deletions

View File

@ -21,7 +21,7 @@ declare namespace Omis {
*
* Use ClassAttributes instead
*/
type PreactHTMLAttributes = ClassAttributes<any>;
type OmiHTMLAttributes = ClassAttributes<any>;
interface Attributes {
key?: Key;
@ -32,7 +32,7 @@ declare namespace Omis {
ref?: Ref<T>;
}
interface PreactDOMAttributes {
interface OmiDOMAttributes {
children?: ComponentChildren;
dangerouslySetInnerHTML?: {
__html: string;
@ -95,16 +95,7 @@ declare namespace Omis {
context: any;
base?: HTMLElement;
// From https://github.com/DefinitelyTyped/DefinitelyTyped/blob/e836acc75a78cf0655b5dfdbe81d69fdd4d8a252/types/react/index.d.ts#L402
// // We MUST keep setState() as a unified signature because it allows proper checking of the method return type.
// // See: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18365#issuecomment-351013257
// // Also, the ` | S` allows intellisense to not be dumbisense
setState<K extends keyof S>(
state: ((prevState: Readonly<S>, props: Readonly<P>) => (Pick<S, K> | S | null)) | (Pick<S, K> | S | null),
callback?: () => void
): void;
forceUpdate(callback?: () => void): void;
update(callback?: () => void): void;
abstract render(props?: RenderableProps<P>, state?: Readonly<S>, context?: any): ComponentChild;
@ -450,7 +441,7 @@ declare global {
type GenericEventHandler = EventHandler<Event>;
type PointerEventHandler = EventHandler<PointerEvent>;
interface DOMAttributes extends Omis.PreactDOMAttributes {
interface DOMAttributes extends Omis.OmiDOMAttributes {
// Image Events
onLoad?: GenericEventHandler;
onError?: GenericEventHandler;
@ -638,7 +629,7 @@ declare global {
onTransitionEndCapture?: TransitionEventHandler;
}
interface HTMLAttributes extends Omis.PreactHTMLAttributes, DOMAttributes {
interface HTMLAttributes extends Omis.OmiHTMLAttributes, DOMAttributes {
// Standard HTML Attributes
accept?: string;
acceptCharset?: string;

View File

@ -1,5 +1,5 @@
/**
* omis v0.4.0 http://omijs.org
* omis v0.5.0 http://omijs.org
* Omi === Preact + Scoped CSS + Store System + Native Support in 3kb javascript.
* By dntzhang https://github.com/dntzhang
* Github: https://github.com/Tencent/omis
@ -34,7 +34,7 @@
* @property {(component: Component) => void} [afterUpdate] Hook invoked after the DOM is updated with a component's latest render.
* @property {(component: Component) => void} [beforeUnmount] Hook invoked immediately before a component is unmounted.
* @property {(rerender: function) => void} [debounceRendering] Hook invoked whenever a rerender is requested. Can be used to debounce rerenders.
* @property {(event: Event) => Event | void} [event] Hook invoked before any Preact event listeners. The return value (if any) replaces the native browser event given to event listeners
* @property {(event: Event) => Event | void} [event] Hook invoked before any Omi event listeners. The return value (if any) replaces the native browser event given to event listeners
*/
/** @type {Options} */
@ -290,7 +290,7 @@
/**
* Check if two nodes are equivalent.
* @param {import('../dom').PreactElement} node DOM Node to compare
* @param {import('../dom').OmiElement} node DOM Node to compare
* @param {import('../vnode').VNode} vnode Virtual DOM node to compare
* @param {boolean} [hydrating=false] If true, ignores component constructors
* when comparing.
@ -308,7 +308,7 @@
/**
* Check if an Element has a given nodeName, case-insensitively.
* @param {import('../dom').PreactElement} node A DOM Element to inspect the name of.
* @param {import('../dom').OmiElement} node A DOM Element to inspect the name of.
* @param {string} nodeName Unnormalized name to compare against.
*/
function isNamedNode(node, nodeName) {
@ -349,8 +349,8 @@
*/
/**
* Properties Preact adds to elements it creates
* @typedef PreactElementExtensions
* Properties Omi adds to elements it creates
* @typedef OmiElementExtensions
* @property {string} [normalizedNodeName] A normalized node name to use in diffing
* @property {EventListenerMap} [_listeners] A map of event listeners added by components to this DOM node
* @property {import('../component').Component} [_component] The component that rendered this DOM node
@ -358,8 +358,8 @@
*/
/**
* A DOM element that has been extended with Preact properties
* @typedef {Element & ElementCSSInlineStyle & PreactElementExtensions} PreactElement
* A DOM element that has been extended with Omi properties
* @typedef {Element & ElementCSSInlineStyle & OmiElementExtensions} OmiElement
*/
/**
@ -367,10 +367,10 @@
* @param {string} nodeName The DOM node to create
* @param {boolean} [isSvg=false] If `true`, creates an element within the SVG
* namespace.
* @returns {PreactElement} The created DOM node
* @returns {OmiElement} The created DOM node
*/
function createNode(nodeName, isSvg) {
/** @type {PreactElement} */
/** @type {OmiElement} */
var node = isSvg ? document.createElementNS('http://www.w3.org/2000/svg', nodeName) : document.createElement(nodeName);
node.normalizedNodeName = nodeName;
return node;
@ -389,7 +389,7 @@
* Set a named attribute on the given Node, with special behavior for some names
* and event handlers. If `value` is `null`, the attribute/handler will be
* removed.
* @param {PreactElement} node An element to mutate
* @param {OmiElement} node An element to mutate
* @param {string} name The name/key to set, such as an event or attribute name
* @param {*} old The last value that was set for this name/node pair
* @param {*} value An attribute value, such as a function to be used as an
@ -494,14 +494,14 @@
/**
* Apply differences in a given vnode (and it's deep children) to a real DOM Node.
* @param {import('../dom').PreactElement} dom A DOM node to mutate into the shape of a `vnode`
* @param {import('../dom').OmiElement} dom A DOM node to mutate into the shape of a `vnode`
* @param {import('../vnode').VNode} vnode A VNode (with descendants forming a tree) representing
* the desired DOM structure
* @param {object} context The current context
* @param {boolean} mountAll Whether or not to immediately mount all components
* @param {Element} parent ?
* @param {boolean} componentRoot ?
* @returns {import('../dom').PreactElement} The created/mutated element
* @returns {import('../dom').OmiElement} The created/mutated element
* @private
*/
function diff(dom, vnode, context, mountAll, parent, componentRoot, store) {
@ -531,7 +531,7 @@
/**
* Internals of `diff()`, separated to allow bypassing diffLevel / mount flushing.
* @param {import('../dom').PreactElement} dom A DOM node to mutate into the shape of a `vnode`
* @param {import('../dom').OmiElement} dom A DOM node to mutate into the shape of a `vnode`
* @param {import('../vnode').VNode} vnode A VNode (with descendants forming a tree) representing the desired DOM structure
* @param {object} context The current context
* @param {boolean} mountAll Whether or not to immediately mount all components
@ -550,7 +550,7 @@
// update if it's already a Text node:
if (dom && dom.splitText !== undefined && dom.parentNode && (!dom._component || componentRoot)) {
/* istanbul ignore if */ /* Browser quirk that can't be covered: https://github.com/developit/preact/commit/fd4f21f5c45dfd75151bd27b4c217d8003aa5eb9 */
/* istanbul ignore if */ /* Browser quirk that can't be covered: https://github.com/developit/Omi/commit/fd4f21f5c45dfd75151bd27b4c217d8003aa5eb9 */
if (dom.nodeValue != vnode) {
dom.nodeValue = vnode;
}
@ -627,7 +627,7 @@
/**
* Apply child and attribute changes between a VNode and a DOM Node to the DOM.
* @param {import('../dom').PreactElement} dom Element whose children should be compared & mutated
* @param {import('../dom').OmiElement} dom Element whose children should be compared & mutated
* @param {Array<import('../vnode').VNode>} vchildren Array of VNodes to compare to `dom.childNodes`
* @param {object} context Implicitly descendant context object (from most
* recent `getChildContext()`)
@ -723,7 +723,7 @@
/**
* Recursively recycle (or just unmount) a node and its descendants.
* @param {import('../dom').PreactElement} node DOM node to start
* @param {import('../dom').OmiElement} node DOM node to start
* unmount/removal from
* @param {boolean} [unmountOnly=false] If `true`, only triggers unmount
* lifecycle, skips removal
@ -762,7 +762,7 @@
/**
* Apply differences in attributes from a VNode to the given DOM Element.
* @param {import('../dom').PreactElement} dom Element with attributes to diff `attrs` against
* @param {import('../dom').OmiElement} dom Element with attributes to diff `attrs` against
* @param {object} attrs The desired end-state key-value attribute pairs
* @param {object} old Current/previous attributes (from previous VNode or
* element's prop cache)
@ -804,17 +804,12 @@
var inst,
i = recyclerComponents.length;
if (Ctor.prototype && Ctor.prototype.render) {
inst = new Ctor(props, context);
Component.call(inst, props, context);
} else {
inst = new Component(props, context);
inst.constructor = Ctor;
inst.render = doRender;
if (Ctor.store) {
inst.store = Ctor.store(inst);
inst.store.update = inst.forceUpdate.bind(inst);
}
inst = new Component(props, context);
inst.constructor = Ctor;
inst.render = doRender;
if (Ctor.store) {
inst.store = Ctor.store(inst);
inst.store.update = inst.update.bind(inst);
}
while (i--) {
@ -1030,7 +1025,7 @@
} else if (!skip) {
// Ensure that pending componentDidMount() hooks of child components
// are called before the componentDidUpdate() hook in the parent.
// Note: disabled as it causes duplicate hooks, see https://github.com/developit/preact/issues/750
// Note: disabled as it causes duplicate hooks, see https://github.com/developit/Omi/issues/750
// flushMounts();
// if (component.componentDidUpdate) {
@ -1049,11 +1044,11 @@
/**
* Apply the Component referenced by a VNode to the DOM.
* @param {import('../dom').PreactElement} dom The DOM node to mutate
* @param {import('../dom').OmiElement} dom The DOM node to mutate
* @param {import('../vnode').VNode} vnode A Component-referencing VNode
* @param {object} context The current context
* @param {boolean} mountAll Whether or not to immediately mount all components
* @returns {import('../dom').PreactElement} The created/mutated element
* @returns {import('../dom').OmiElement} The created/mutated element
* @private
*/
function buildComponentFromVNode(dom, vnode, context, mountAll) {
@ -1130,7 +1125,7 @@
/**
* Base Component class.
* Provides `setState()` and `forceUpdate()`, which trigger rendering.
* Provides `update()`, which trigger rendering.
* @typedef {object} Component
* @param {object} props The initial component props
* @param {object} context The initial context from parent components' getChildContext
@ -1172,35 +1167,17 @@
extend(Component.prototype, {
/**
* Update component state and schedule a re-render.
* @param {object} state A dict of state properties to be shallowly merged
* into the current state, or a function that will produce such a dict. The
* function is called with the current state and props.
* @param {() => void} callback A function to be called once component state is
* updated
*/
setState: function setState(state, callback) {
if (!this.prevState) this.prevState = this.state;
this.state = extend(extend({}, this.state), typeof state === 'function' ? state(this.state, this.props) : state);
if (callback) this._renderCallbacks.push(callback);
enqueueRender(this);
},
/**
* Immediately perform a synchronous re-render of the component.
* @param {() => void} callback A function to be called after component is
* re-rendered.
* @private
*/
forceUpdate: function forceUpdate(callback) {
update: function update(callback) {
if (callback) this._renderCallbacks.push(callback);
renderComponent(this, 2);
},
update: function update(callback) {
this.forceUpdate(callback);
},
/**
* Accepts `props` and `state`, and returns a new Virtual DOM tree to build.
@ -1218,8 +1195,8 @@
/**
* Render JSX into a `parent` Element.
* @param {import('./vnode').VNode} vnode A (JSX) VNode to render
* @param {import('./dom').PreactElement} parent DOM element to render into
* @param {import('./dom').PreactElement} [merge] Attempt to re-use an existing DOM tree rooted at
* @param {import('./dom').OmiElement} parent DOM element to render into
* @param {import('./dom').OmiElement} [merge] Attempt to re-use an existing DOM tree rooted at
* `merge`
* @public
*

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
/**
* omis v0.4.0 http://omijs.org
* omis v0.5.0 http://omijs.org
* Omi === Preact + Scoped CSS + Store System + Native Support in 3kb javascript.
* By dntzhang https://github.com/dntzhang
* Github: https://github.com/Tencent/omis
@ -31,7 +31,7 @@ var VNode = function VNode() {};
* @property {(component: Component) => void} [afterUpdate] Hook invoked after the DOM is updated with a component's latest render.
* @property {(component: Component) => void} [beforeUnmount] Hook invoked immediately before a component is unmounted.
* @property {(rerender: function) => void} [debounceRendering] Hook invoked whenever a rerender is requested. Can be used to debounce rerenders.
* @property {(event: Event) => Event | void} [event] Hook invoked before any Preact event listeners. The return value (if any) replaces the native browser event given to event listeners
* @property {(event: Event) => Event | void} [event] Hook invoked before any Omi event listeners. The return value (if any) replaces the native browser event given to event listeners
*/
/** @type {Options} */
@ -287,7 +287,7 @@ function rerender() {
/**
* Check if two nodes are equivalent.
* @param {import('../dom').PreactElement} node DOM Node to compare
* @param {import('../dom').OmiElement} node DOM Node to compare
* @param {import('../vnode').VNode} vnode Virtual DOM node to compare
* @param {boolean} [hydrating=false] If true, ignores component constructors
* when comparing.
@ -305,7 +305,7 @@ function isSameNodeType(node, vnode, hydrating) {
/**
* Check if an Element has a given nodeName, case-insensitively.
* @param {import('../dom').PreactElement} node A DOM Element to inspect the name of.
* @param {import('../dom').OmiElement} node A DOM Element to inspect the name of.
* @param {string} nodeName Unnormalized name to compare against.
*/
function isNamedNode(node, nodeName) {
@ -346,8 +346,8 @@ function getNodeProps(vnode) {
*/
/**
* Properties Preact adds to elements it creates
* @typedef PreactElementExtensions
* Properties Omi adds to elements it creates
* @typedef OmiElementExtensions
* @property {string} [normalizedNodeName] A normalized node name to use in diffing
* @property {EventListenerMap} [_listeners] A map of event listeners added by components to this DOM node
* @property {import('../component').Component} [_component] The component that rendered this DOM node
@ -355,8 +355,8 @@ function getNodeProps(vnode) {
*/
/**
* A DOM element that has been extended with Preact properties
* @typedef {Element & ElementCSSInlineStyle & PreactElementExtensions} PreactElement
* A DOM element that has been extended with Omi properties
* @typedef {Element & ElementCSSInlineStyle & OmiElementExtensions} OmiElement
*/
/**
@ -364,10 +364,10 @@ function getNodeProps(vnode) {
* @param {string} nodeName The DOM node to create
* @param {boolean} [isSvg=false] If `true`, creates an element within the SVG
* namespace.
* @returns {PreactElement} The created DOM node
* @returns {OmiElement} The created DOM node
*/
function createNode(nodeName, isSvg) {
/** @type {PreactElement} */
/** @type {OmiElement} */
var node = isSvg ? document.createElementNS('http://www.w3.org/2000/svg', nodeName) : document.createElement(nodeName);
node.normalizedNodeName = nodeName;
return node;
@ -386,7 +386,7 @@ function removeNode(node) {
* Set a named attribute on the given Node, with special behavior for some names
* and event handlers. If `value` is `null`, the attribute/handler will be
* removed.
* @param {PreactElement} node An element to mutate
* @param {OmiElement} node An element to mutate
* @param {string} name The name/key to set, such as an event or attribute name
* @param {*} old The last value that was set for this name/node pair
* @param {*} value An attribute value, such as a function to be used as an
@ -491,14 +491,14 @@ function flushMounts() {
/**
* Apply differences in a given vnode (and it's deep children) to a real DOM Node.
* @param {import('../dom').PreactElement} dom A DOM node to mutate into the shape of a `vnode`
* @param {import('../dom').OmiElement} dom A DOM node to mutate into the shape of a `vnode`
* @param {import('../vnode').VNode} vnode A VNode (with descendants forming a tree) representing
* the desired DOM structure
* @param {object} context The current context
* @param {boolean} mountAll Whether or not to immediately mount all components
* @param {Element} parent ?
* @param {boolean} componentRoot ?
* @returns {import('../dom').PreactElement} The created/mutated element
* @returns {import('../dom').OmiElement} The created/mutated element
* @private
*/
function diff(dom, vnode, context, mountAll, parent, componentRoot, store) {
@ -528,7 +528,7 @@ function diff(dom, vnode, context, mountAll, parent, componentRoot, store) {
/**
* Internals of `diff()`, separated to allow bypassing diffLevel / mount flushing.
* @param {import('../dom').PreactElement} dom A DOM node to mutate into the shape of a `vnode`
* @param {import('../dom').OmiElement} dom A DOM node to mutate into the shape of a `vnode`
* @param {import('../vnode').VNode} vnode A VNode (with descendants forming a tree) representing the desired DOM structure
* @param {object} context The current context
* @param {boolean} mountAll Whether or not to immediately mount all components
@ -547,7 +547,7 @@ function idiff(dom, vnode, context, mountAll, componentRoot, store) {
// update if it's already a Text node:
if (dom && dom.splitText !== undefined && dom.parentNode && (!dom._component || componentRoot)) {
/* istanbul ignore if */ /* Browser quirk that can't be covered: https://github.com/developit/preact/commit/fd4f21f5c45dfd75151bd27b4c217d8003aa5eb9 */
/* istanbul ignore if */ /* Browser quirk that can't be covered: https://github.com/developit/Omi/commit/fd4f21f5c45dfd75151bd27b4c217d8003aa5eb9 */
if (dom.nodeValue != vnode) {
dom.nodeValue = vnode;
}
@ -624,7 +624,7 @@ function idiff(dom, vnode, context, mountAll, componentRoot, store) {
/**
* Apply child and attribute changes between a VNode and a DOM Node to the DOM.
* @param {import('../dom').PreactElement} dom Element whose children should be compared & mutated
* @param {import('../dom').OmiElement} dom Element whose children should be compared & mutated
* @param {Array<import('../vnode').VNode>} vchildren Array of VNodes to compare to `dom.childNodes`
* @param {object} context Implicitly descendant context object (from most
* recent `getChildContext()`)
@ -720,7 +720,7 @@ function innerDiffNode(dom, vchildren, context, mountAll, isHydrating, store) {
/**
* Recursively recycle (or just unmount) a node and its descendants.
* @param {import('../dom').PreactElement} node DOM node to start
* @param {import('../dom').OmiElement} node DOM node to start
* unmount/removal from
* @param {boolean} [unmountOnly=false] If `true`, only triggers unmount
* lifecycle, skips removal
@ -759,7 +759,7 @@ function removeChildren(node) {
/**
* Apply differences in attributes from a VNode to the given DOM Element.
* @param {import('../dom').PreactElement} dom Element with attributes to diff `attrs` against
* @param {import('../dom').OmiElement} dom Element with attributes to diff `attrs` against
* @param {object} attrs The desired end-state key-value attribute pairs
* @param {object} old Current/previous attributes (from previous VNode or
* element's prop cache)
@ -801,17 +801,12 @@ function createComponent(Ctor, props, context) {
var inst,
i = recyclerComponents.length;
if (Ctor.prototype && Ctor.prototype.render) {
inst = new Ctor(props, context);
Component.call(inst, props, context);
} else {
inst = new Component(props, context);
inst.constructor = Ctor;
inst.render = doRender;
if (Ctor.store) {
inst.store = Ctor.store(inst);
inst.store.update = inst.forceUpdate.bind(inst);
}
inst = new Component(props, context);
inst.constructor = Ctor;
inst.render = doRender;
if (Ctor.store) {
inst.store = Ctor.store(inst);
inst.store.update = inst.update.bind(inst);
}
while (i--) {
@ -1027,7 +1022,7 @@ function renderComponent(component, renderMode, mountAll, isChild) {
} else if (!skip) {
// Ensure that pending componentDidMount() hooks of child components
// are called before the componentDidUpdate() hook in the parent.
// Note: disabled as it causes duplicate hooks, see https://github.com/developit/preact/issues/750
// Note: disabled as it causes duplicate hooks, see https://github.com/developit/Omi/issues/750
// flushMounts();
// if (component.componentDidUpdate) {
@ -1046,11 +1041,11 @@ function renderComponent(component, renderMode, mountAll, isChild) {
/**
* Apply the Component referenced by a VNode to the DOM.
* @param {import('../dom').PreactElement} dom The DOM node to mutate
* @param {import('../dom').OmiElement} dom The DOM node to mutate
* @param {import('../vnode').VNode} vnode A Component-referencing VNode
* @param {object} context The current context
* @param {boolean} mountAll Whether or not to immediately mount all components
* @returns {import('../dom').PreactElement} The created/mutated element
* @returns {import('../dom').OmiElement} The created/mutated element
* @private
*/
function buildComponentFromVNode(dom, vnode, context, mountAll) {
@ -1127,7 +1122,7 @@ function unmountComponent(component) {
/**
* Base Component class.
* Provides `setState()` and `forceUpdate()`, which trigger rendering.
* Provides `update()`, which trigger rendering.
* @typedef {object} Component
* @param {object} props The initial component props
* @param {object} context The initial context from parent components' getChildContext
@ -1169,35 +1164,17 @@ function Component(props, context) {
extend(Component.prototype, {
/**
* Update component state and schedule a re-render.
* @param {object} state A dict of state properties to be shallowly merged
* into the current state, or a function that will produce such a dict. The
* function is called with the current state and props.
* @param {() => void} callback A function to be called once component state is
* updated
*/
setState: function setState(state, callback) {
if (!this.prevState) this.prevState = this.state;
this.state = extend(extend({}, this.state), typeof state === 'function' ? state(this.state, this.props) : state);
if (callback) this._renderCallbacks.push(callback);
enqueueRender(this);
},
/**
* Immediately perform a synchronous re-render of the component.
* @param {() => void} callback A function to be called after component is
* re-rendered.
* @private
*/
forceUpdate: function forceUpdate(callback) {
update: function update(callback) {
if (callback) this._renderCallbacks.push(callback);
renderComponent(this, 2);
},
update: function update(callback) {
this.forceUpdate(callback);
},
/**
* Accepts `props` and `state`, and returns a new Virtual DOM tree to build.
@ -1215,8 +1192,8 @@ extend(Component.prototype, {
/**
* Render JSX into a `parent` Element.
* @param {import('./vnode').VNode} vnode A (JSX) VNode to render
* @param {import('./dom').PreactElement} parent DOM element to render into
* @param {import('./dom').PreactElement} [merge] Attempt to re-use an existing DOM tree rooted at
* @param {import('./dom').OmiElement} parent DOM element to render into
* @param {import('./dom').OmiElement} [merge] Attempt to re-use an existing DOM tree rooted at
* `merge`
* @public
*

File diff suppressed because one or more lines are too long

View File

@ -258,17 +258,12 @@
}
function createComponent(Ctor, props, context) {
var inst, i = recyclerComponents.length;
if (Ctor.prototype && Ctor.prototype.render) {
inst = new Ctor(props, context);
Component.call(inst, props, context);
} else {
inst = new Component(props, context);
inst.constructor = Ctor;
inst.render = doRender;
if (Ctor.store) {
inst.store = Ctor.store(inst);
inst.store.update = inst.forceUpdate.bind(inst);
}
inst = new Component(props, context);
inst.constructor = Ctor;
inst.render = doRender;
if (Ctor.store) {
inst.store = Ctor.store(inst);
inst.store.update = inst.update.bind(inst);
}
while (i--) if (recyclerComponents[i].constructor === Ctor) {
inst.__b = recyclerComponents[i].__b;
@ -454,19 +449,10 @@
var recyclerComponents = [];
var id = 0;
extend(Component.prototype, {
setState: function(state, callback) {
if (!this.__s) this.__s = this.state;
this.state = extend(extend({}, this.state), 'function' == typeof state ? state(this.state, this.props) : state);
if (callback) this.__h.push(callback);
enqueueRender(this);
},
forceUpdate: function(callback) {
update: function(callback) {
if (callback) this.__h.push(callback);
renderComponent(this, 2);
},
update: function(callback) {
this.forceUpdate(callback);
},
render: function() {}
});
var Omis = {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "omis",
"version": "0.4.0",
"version": "0.5.0",
"description": "Functional Component with store, scoped css and easy hyperscript.",
"main": "dist/omis.js",
"jsnext:main": "dist/omis.esm.js",

View File

@ -13,8 +13,8 @@ import options from '../options';
*/
/**
* Properties Preact adds to elements it creates
* @typedef PreactElementExtensions
* Properties Omi adds to elements it creates
* @typedef OmiElementExtensions
* @property {string} [normalizedNodeName] A normalized node name to use in diffing
* @property {EventListenerMap} [_listeners] A map of event listeners added by components to this DOM node
* @property {import('../component').Component} [_component] The component that rendered this DOM node
@ -22,8 +22,8 @@ import options from '../options';
*/
/**
* A DOM element that has been extended with Preact properties
* @typedef {Element & ElementCSSInlineStyle & PreactElementExtensions} PreactElement
* A DOM element that has been extended with Omi properties
* @typedef {Element & ElementCSSInlineStyle & OmiElementExtensions} OmiElement
*/
/**
@ -31,10 +31,10 @@ import options from '../options';
* @param {string} nodeName The DOM node to create
* @param {boolean} [isSvg=false] If `true`, creates an element within the SVG
* namespace.
* @returns {PreactElement} The created DOM node
* @returns {OmiElement} The created DOM node
*/
export function createNode(nodeName, isSvg) {
/** @type {PreactElement} */
/** @type {OmiElement} */
let node = isSvg ? document.createElementNS('http://www.w3.org/2000/svg', nodeName) : document.createElement(nodeName);
node.normalizedNodeName = nodeName;
return node;
@ -55,7 +55,7 @@ export function removeNode(node) {
* Set a named attribute on the given Node, with special behavior for some names
* and event handlers. If `value` is `null`, the attribute/handler will be
* removed.
* @param {PreactElement} node An element to mutate
* @param {OmiElement} node An element to mutate
* @param {string} name The name/key to set, such as an event or attribute name
* @param {*} old The last value that was set for this name/node pair
* @param {*} value An attribute value, such as a function to be used as an

View File

@ -21,7 +21,7 @@ declare namespace Omis {
*
* Use ClassAttributes instead
*/
type PreactHTMLAttributes = ClassAttributes<any>;
type OmiHTMLAttributes = ClassAttributes<any>;
interface Attributes {
key?: Key;
@ -32,7 +32,7 @@ declare namespace Omis {
ref?: Ref<T>;
}
interface PreactDOMAttributes {
interface OmiDOMAttributes {
children?: ComponentChildren;
dangerouslySetInnerHTML?: {
__html: string;
@ -441,7 +441,7 @@ declare global {
type GenericEventHandler = EventHandler<Event>;
type PointerEventHandler = EventHandler<PointerEvent>;
interface DOMAttributes extends Omis.PreactDOMAttributes {
interface DOMAttributes extends Omis.OmiDOMAttributes {
// Image Events
onLoad?: GenericEventHandler;
onError?: GenericEventHandler;
@ -629,7 +629,7 @@ declare global {
onTransitionEndCapture?: TransitionEventHandler;
}
interface HTMLAttributes extends Omis.PreactHTMLAttributes, DOMAttributes {
interface HTMLAttributes extends Omis.OmiHTMLAttributes, DOMAttributes {
// Standard HTML Attributes
accept?: string;
acceptCharset?: string;

View File

@ -13,7 +13,7 @@
* @property {(component: Component) => void} [afterUpdate] Hook invoked after the DOM is updated with a component's latest render.
* @property {(component: Component) => void} [beforeUnmount] Hook invoked immediately before a component is unmounted.
* @property {(rerender: function) => void} [debounceRendering] Hook invoked whenever a rerender is requested. Can be used to debounce rerenders.
* @property {(event: Event) => Event | void} [event] Hook invoked before any Preact event listeners. The return value (if any) replaces the native browser event given to event listeners
* @property {(event: Event) => Event | void} [event] Hook invoked before any Omi event listeners. The return value (if any) replaces the native browser event given to event listeners
*/
/** @type {Options} */

View File

@ -3,8 +3,8 @@ import { diff } from './vdom/diff';
/**
* Render JSX into a `parent` Element.
* @param {import('./vnode').VNode} vnode A (JSX) VNode to render
* @param {import('./dom').PreactElement} parent DOM element to render into
* @param {import('./dom').PreactElement} [merge] Attempt to re-use an existing DOM tree rooted at
* @param {import('./dom').OmiElement} parent DOM element to render into
* @param {import('./dom').OmiElement} [merge] Attempt to re-use an existing DOM tree rooted at
* `merge`
* @public
*

View File

@ -208,7 +208,7 @@ export function renderComponent(component, renderMode, mountAll, isChild) {
else if (!skip) {
// Ensure that pending componentDidMount() hooks of child components
// are called before the componentDidUpdate() hook in the parent.
// Note: disabled as it causes duplicate hooks, see https://github.com/developit/preact/issues/750
// Note: disabled as it causes duplicate hooks, see https://github.com/developit/Omi/issues/750
// flushMounts();
// if (component.componentDidUpdate) {
@ -229,11 +229,11 @@ export function renderComponent(component, renderMode, mountAll, isChild) {
/**
* Apply the Component referenced by a VNode to the DOM.
* @param {import('../dom').PreactElement} dom The DOM node to mutate
* @param {import('../dom').OmiElement} dom The DOM node to mutate
* @param {import('../vnode').VNode} vnode A Component-referencing VNode
* @param {object} context The current context
* @param {boolean} mountAll Whether or not to immediately mount all components
* @returns {import('../dom').PreactElement} The created/mutated element
* @returns {import('../dom').OmiElement} The created/mutated element
* @private
*/
export function buildComponentFromVNode(dom, vnode, context, mountAll) {

View File

@ -42,14 +42,14 @@ export function flushMounts() {
/**
* Apply differences in a given vnode (and it's deep children) to a real DOM Node.
* @param {import('../dom').PreactElement} dom A DOM node to mutate into the shape of a `vnode`
* @param {import('../dom').OmiElement} dom A DOM node to mutate into the shape of a `vnode`
* @param {import('../vnode').VNode} vnode A VNode (with descendants forming a tree) representing
* the desired DOM structure
* @param {object} context The current context
* @param {boolean} mountAll Whether or not to immediately mount all components
* @param {Element} parent ?
* @param {boolean} componentRoot ?
* @returns {import('../dom').PreactElement} The created/mutated element
* @returns {import('../dom').OmiElement} The created/mutated element
* @private
*/
export function diff(dom, vnode, context, mountAll, parent, componentRoot, store) {
@ -80,7 +80,7 @@ export function diff(dom, vnode, context, mountAll, parent, componentRoot, store
/**
* Internals of `diff()`, separated to allow bypassing diffLevel / mount flushing.
* @param {import('../dom').PreactElement} dom A DOM node to mutate into the shape of a `vnode`
* @param {import('../dom').OmiElement} dom A DOM node to mutate into the shape of a `vnode`
* @param {import('../vnode').VNode} vnode A VNode (with descendants forming a tree) representing the desired DOM structure
* @param {object} context The current context
* @param {boolean} mountAll Whether or not to immediately mount all components
@ -100,7 +100,7 @@ function idiff(dom, vnode, context, mountAll, componentRoot, store) {
// update if it's already a Text node:
if (dom && dom.splitText!==undefined && dom.parentNode && (!dom._component || componentRoot)) {
/* istanbul ignore if */ /* Browser quirk that can't be covered: https://github.com/developit/preact/commit/fd4f21f5c45dfd75151bd27b4c217d8003aa5eb9 */
/* istanbul ignore if */ /* Browser quirk that can't be covered: https://github.com/developit/Omi/commit/fd4f21f5c45dfd75151bd27b4c217d8003aa5eb9 */
if (dom.nodeValue!=vnode) {
dom.nodeValue = vnode;
}
@ -183,7 +183,7 @@ function idiff(dom, vnode, context, mountAll, componentRoot, store) {
/**
* Apply child and attribute changes between a VNode and a DOM Node to the DOM.
* @param {import('../dom').PreactElement} dom Element whose children should be compared & mutated
* @param {import('../dom').OmiElement} dom Element whose children should be compared & mutated
* @param {Array<import('../vnode').VNode>} vchildren Array of VNodes to compare to `dom.childNodes`
* @param {object} context Implicitly descendant context object (from most
* recent `getChildContext()`)
@ -279,7 +279,7 @@ function innerDiffNode(dom, vchildren, context, mountAll, isHydrating, store) {
/**
* Recursively recycle (or just unmount) a node and its descendants.
* @param {import('../dom').PreactElement} node DOM node to start
* @param {import('../dom').OmiElement} node DOM node to start
* unmount/removal from
* @param {boolean} [unmountOnly=false] If `true`, only triggers unmount
* lifecycle, skips removal
@ -321,7 +321,7 @@ export function removeChildren(node) {
/**
* Apply differences in attributes from a VNode to the given DOM Element.
* @param {import('../dom').PreactElement} dom Element with attributes to diff `attrs` against
* @param {import('../dom').OmiElement} dom Element with attributes to diff `attrs` against
* @param {object} attrs The desired end-state key-value attribute pairs
* @param {object} old Current/previous attributes (from previous VNode or
* element's prop cache)

View File

@ -3,7 +3,7 @@ import { extend } from '../util';
/**
* Check if two nodes are equivalent.
* @param {import('../dom').PreactElement} node DOM Node to compare
* @param {import('../dom').OmiElement} node DOM Node to compare
* @param {import('../vnode').VNode} vnode Virtual DOM node to compare
* @param {boolean} [hydrating=false] If true, ignores component constructors
* when comparing.
@ -22,7 +22,7 @@ export function isSameNodeType(node, vnode, hydrating) {
/**
* Check if an Element has a given nodeName, case-insensitively.
* @param {import('../dom').PreactElement} node A DOM Element to inspect the name of.
* @param {import('../dom').OmiElement} node A DOM Element to inspect the name of.
* @param {string} nodeName Unnormalized name to compare against.
*/
export function isNamedNode(node, nodeName) {