omi v3.0.6

This commit is contained in:
dntzhang 2018-05-20 14:08:36 +08:00
parent 151fc791f0
commit 5b90453797
16 changed files with 114 additions and 109 deletions

View File

@ -264,8 +264,8 @@ npm i omi
或从 CDN 获取:
* [https://unpkg.com/omi@3.0.5/dist/omi.min.js](https://unpkg.com/omi@3.0.5/dist/omi.min.js)
* [https://unpkg.com/omi@3.0.5/dist/omi.js](https://unpkg.com/omi@3.0.5/dist/omi.js)
* [https://unpkg.com/omi@3.0.6/dist/omi.min.js](https://unpkg.com/omi@3.0.6/dist/omi.min.js)
* [https://unpkg.com/omi@3.0.6/dist/omi.js](https://unpkg.com/omi@3.0.6/dist/omi.js)
## Official Plugins

View File

@ -261,8 +261,8 @@ npm i omi
or get it from CDN:
* [https://unpkg.com/omi@3.0.5/dist/omi.min.js](https://unpkg.com/omi@3.0.5/dist/omi.min.js)
* [https://unpkg.com/omi@3.0.5/dist/omi.js](https://unpkg.com/omi@3.0.5/dist/omi.js)
* [https://unpkg.com/omi@3.0.6/dist/omi.min.js](https://unpkg.com/omi@3.0.6/dist/omi.min.js)
* [https://unpkg.com/omi@3.0.6/dist/omi.js](https://unpkg.com/omi@3.0.6/dist/omi.js)
## Official Plugins

View File

@ -1,3 +1,7 @@
# omi 3.0.6
Solving the root component constructor name conflict of static style rendering.
# omi 3.0.5
Solving the component constructor name conflict of static style rendering.

55
dist/omi.dev.js vendored
View File

@ -1,5 +1,5 @@
/**
* omi v3.0.5 http://omijs.org
* omi v3.0.6 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/omi
@ -920,6 +920,25 @@
return this.constructor(props, context);
}
var styleId = 0;
function getCtorName(ctor) {
for (var i = 0, len = options.styleCache.length; i < len; i++) {
var item = options.styleCache[i];
if (item.ctor === ctor) {
return item.attrName;
}
}
var attrName = 'static_' + styleId;
options.styleCache.push({ ctor: ctor, attrName: attrName });
styleId++;
return attrName;
}
// many thanks to https://github.com/thomaspark/scoper/
function scoper(css, prefix) {
prefix = '[' + prefix.toLowerCase() + ']';
@ -1022,25 +1041,6 @@
}
}
var id = 0;
function getCtorName(ctor) {
for (var i = 0, len = options.styleCache.length; i < len; i++) {
var item = options.styleCache[i];
if (item.ctor === ctor) {
return item.attrName;
}
}
var attrName = 'static_' + id;
options.styleCache.push({ ctor: ctor, attrName: attrName });
id++;
return attrName;
}
/** Set a component's `props` (generally derived from JSX attributes).
* @param {Object} props
* @param {Object} [opts]
@ -1312,9 +1312,9 @@
if (component.__ref) component.__ref(null);
}
var id$1 = 0;
var id = 0;
function getId() {
return id$1++;
return id++;
}
/** Base Component class.
* Provides `setState()` and `forceUpdate()`, which trigger rendering.
@ -1449,13 +1449,14 @@
if (vnode.componentWillMount) vnode.componentWillMount();
if (vnode.install) vnode.install();
var rendered = vnode.render(vnode.props, vnode.state, vnode.context);
if (vnode.style) {
addScopedAttr(rendered, vnode.style(), '_style_' + vnode._id, vnode);
}
//don't rerender
if (vnode.staticStyle) {
addScopedAttrStatic(rendered, vnode.staticStyle(), '_style_' + vnode.constructor.name, !vnode.base);
addScopedAttrStatic(rendered, vnode.staticStyle(), '_style_' + getCtorName(vnode.constructor));
}
if (vnode.style) {
addScopedAttr(rendered, vnode.style(), '_style_' + vnode._id, vnode);
}
vnode.base = diff(merge.merge, rendered, {}, false, parent, false);
@ -1484,7 +1485,7 @@
instances: instances
};
options.root.Omi.version = '3.0.5';
options.root.Omi.version = '3.0.6';
var Omi = {
h: h,

2
dist/omi.dev.js.map vendored

File diff suppressed because one or more lines are too long

55
dist/omi.esm.js vendored
View File

@ -1,5 +1,5 @@
/**
* omi v3.0.5 http://omijs.org
* omi v3.0.6 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/omi
@ -917,6 +917,25 @@ function doRender(props, state, context) {
return this.constructor(props, context);
}
var styleId = 0;
function getCtorName(ctor) {
for (var i = 0, len = options.styleCache.length; i < len; i++) {
var item = options.styleCache[i];
if (item.ctor === ctor) {
return item.attrName;
}
}
var attrName = 'static_' + styleId;
options.styleCache.push({ ctor: ctor, attrName: attrName });
styleId++;
return attrName;
}
// many thanks to https://github.com/thomaspark/scoper/
function scoper(css, prefix) {
prefix = '[' + prefix.toLowerCase() + ']';
@ -1019,25 +1038,6 @@ function scopeVdom(attr, vdom) {
}
}
var id = 0;
function getCtorName(ctor) {
for (var i = 0, len = options.styleCache.length; i < len; i++) {
var item = options.styleCache[i];
if (item.ctor === ctor) {
return item.attrName;
}
}
var attrName = 'static_' + id;
options.styleCache.push({ ctor: ctor, attrName: attrName });
id++;
return attrName;
}
/** Set a component's `props` (generally derived from JSX attributes).
* @param {Object} props
* @param {Object} [opts]
@ -1309,9 +1309,9 @@ function unmountComponent(component) {
if (component.__ref) component.__ref(null);
}
var id$1 = 0;
var id = 0;
function getId() {
return id$1++;
return id++;
}
/** Base Component class.
* Provides `setState()` and `forceUpdate()`, which trigger rendering.
@ -1446,13 +1446,14 @@ function render(vnode, parent, merge) {
if (vnode.componentWillMount) vnode.componentWillMount();
if (vnode.install) vnode.install();
var rendered = vnode.render(vnode.props, vnode.state, vnode.context);
if (vnode.style) {
addScopedAttr(rendered, vnode.style(), '_style_' + vnode._id, vnode);
}
//don't rerender
if (vnode.staticStyle) {
addScopedAttrStatic(rendered, vnode.staticStyle(), '_style_' + vnode.constructor.name, !vnode.base);
addScopedAttrStatic(rendered, vnode.staticStyle(), '_style_' + getCtorName(vnode.constructor));
}
if (vnode.style) {
addScopedAttr(rendered, vnode.style(), '_style_' + vnode._id, vnode);
}
vnode.base = diff(merge.merge, rendered, {}, false, parent, false);
@ -1481,7 +1482,7 @@ options.root.Omi = {
instances: instances
};
options.root.Omi.version = '3.0.5';
options.root.Omi.version = '3.0.6';
var omi = {
h: h,

2
dist/omi.esm.js.map vendored

File diff suppressed because one or more lines are too long

34
dist/omi.js vendored
View File

@ -289,6 +289,19 @@
function doRender(props, state, context) {
return this.constructor(props, context);
}
function getCtorName(ctor) {
for (var i = 0, len = options.styleCache.length; i < len; i++) {
var item = options.styleCache[i];
if (item.ctor === ctor) return item.attrName;
}
var attrName = 'static_' + styleId;
options.styleCache.push({
ctor: ctor,
attrName: attrName
});
styleId++;
return attrName;
}
function scoper(css, prefix) {
prefix = '[' + prefix.toLowerCase() + ']';
css = css.replace(/\/\*[^*]*\*+([^\/][^*]*\*+)*\//g, '');
@ -342,19 +355,6 @@
});
}
}
function getCtorName(ctor) {
for (var i = 0, len = options.styleCache.length; i < len; i++) {
var item = options.styleCache[i];
if (item.ctor === ctor) return item.attrName;
}
var attrName = 'static_' + id;
options.styleCache.push({
ctor: ctor,
attrName: attrName
});
id++;
return attrName;
}
function setComponentProps(component, props, opts, context, mountAll) {
if (!component.__x) {
component.__x = !0;
@ -486,7 +486,7 @@
if (component.__r) component.__r(null);
}
function getId() {
return id$1++;
return id++;
}
function Component(props, context) {
this.context = context;
@ -513,8 +513,8 @@
if (vnode.componentWillMount) vnode.componentWillMount();
if (vnode.install) vnode.install();
var rendered = vnode.render(vnode.props, vnode.state, vnode.context);
if (vnode.staticStyle) addScopedAttrStatic(rendered, vnode.staticStyle(), '_style_' + getCtorName(vnode.constructor));
if (vnode.style) addScopedAttr(rendered, vnode.style(), '_style_' + vnode.s, vnode);
if (vnode.staticStyle) addScopedAttrStatic(rendered, vnode.staticStyle(), '_style_' + vnode.constructor.name, !vnode.base);
vnode.base = diff(merge.merge, rendered, {}, !1, parent, !1);
if (vnode.componentDidMount) vnode.componentDidMount();
if (vnode.installed) vnode.installed();
@ -679,8 +679,8 @@
var isSvgMode = !1;
var hydrating = !1;
var components = {};
var styleId = 0;
var id = 0;
var id$1 = 0;
extend(Component.prototype, {
setState: function(state, callback) {
var s = this.state;
@ -710,7 +710,7 @@
options: options,
instances: instances
};
options.root.Omi.version = '3.0.5';
options.root.Omi.version = '3.0.6';
var Omi = {
h: h,
createElement: h,

2
dist/omi.js.map vendored

File diff suppressed because one or more lines are too long

2
dist/omi.min.js vendored

File diff suppressed because one or more lines are too long

2
dist/omi.min.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "omi",
"version": "3.0.5",
"version": "3.0.6",
"description": "Omi === Preact + Scoped CSS + Store System + Native Support in 3kb javascript.",
"main": "dist/omi.js",
"jsnext:main": "dist/omi.esm.js",

View File

@ -18,7 +18,7 @@ options.root.Omi = {
instances
};
options.root.Omi.version = '3.0.5';
options.root.Omi.version = '3.0.6';
export default {
h,

View File

@ -1,7 +1,7 @@
import { diff } from './vdom/diff';
import { Component } from './component';
import options from './options';
import {addScopedAttr, addScopedAttrStatic} from './style';
import {addScopedAttr, addScopedAttrStatic, getCtorName} from './style';
/** Render JSX into a `parent` Element.
* @param {VNode} vnode A (JSX) VNode to render
@ -53,13 +53,14 @@ export function render(vnode, parent, merge) {
if (vnode.componentWillMount) vnode.componentWillMount();
if (vnode.install) vnode.install();
const rendered = vnode.render(vnode.props, vnode.state, vnode.context);
if (vnode.style){
addScopedAttr(rendered,vnode.style(),'_style_'+vnode._id,vnode);
}
//don't rerender
if (vnode.staticStyle){
addScopedAttrStatic(rendered,vnode.staticStyle(),'_style_'+vnode.constructor.name, !vnode.base);
addScopedAttrStatic(rendered,vnode.staticStyle(),'_style_'+getCtorName(vnode.constructor));
}
if (vnode.style){
addScopedAttr(rendered,vnode.style(),'_style_'+vnode._id,vnode);
}
vnode.base = diff(merge.merge, rendered, {}, false, parent, false);

View File

@ -1,5 +1,24 @@
import options from './options';
let styleId = 0;
export function getCtorName(ctor) {
for (let i = 0, len = options.styleCache.length; i < len; i++) {
let item = options.styleCache[i];
if (item.ctor === ctor) {
return item.attrName;
}
}
let attrName = 'static_' + styleId;
options.styleCache.push({ ctor, attrName });
styleId++;
return attrName;
}
// many thanks to https://github.com/thomaspark/scoper/
export function scoper(css, prefix) {
prefix = '['+prefix.toLowerCase()+']';

View File

@ -6,28 +6,7 @@ import { getNodeProps } from './index';
import { diff, mounts, diffLevel, flushMounts, recollectNodeTree, removeChildren } from './diff';
import { createComponent, collectComponent } from './component-recycler';
import { removeNode } from '../dom/index';
import {addScopedAttr, addScopedAttrStatic} from '../style';
let id = 0;
function getCtorName(ctor) {
for (let i = 0, len = options.styleCache.length; i < len; i++) {
let item = options.styleCache[i];
if (item.ctor === ctor) {
return item.attrName;
}
}
let attrName = 'static_' + id;
options.styleCache.push({ ctor, attrName });
id++;
return attrName;
}
import {addScopedAttr, addScopedAttrStatic, getCtorName} from '../style';
/** Set a component's `props` (generally derived from JSX attributes).
* @param {Object} props