omi 3.0.5

This commit is contained in:
dntzhang 2018-05-20 13:29:19 +08:00
parent c83d2a2e08
commit 66bab76c53
16 changed files with 128 additions and 43 deletions

View File

@ -264,8 +264,8 @@ npm i omi
或从 CDN 获取:
* [https://unpkg.com/omi@3.0.4/dist/omi.min.js](https://unpkg.com/omi@3.0.4/dist/omi.min.js)
* [https://unpkg.com/omi@3.0.4/dist/omi.js](https://unpkg.com/omi@3.0.4/dist/omi.js)
* [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)
## Official Plugins

View File

@ -261,8 +261,8 @@ npm i omi
or get it from CDN:
* [https://unpkg.com/omi@3.0.4/dist/omi.min.js](https://unpkg.com/omi@3.0.4/dist/omi.min.js)
* [https://unpkg.com/omi@3.0.4/dist/omi.js](https://unpkg.com/omi@3.0.4/dist/omi.js)
* [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)
## Official Plugins

View File

@ -1,3 +1,7 @@
# omi 3.0.5
Solving the component constructor name conflict of static style rendering.
# omi 3.0.4
* modify the render method args:

41
dist/omi.dev.js vendored
View File

@ -1,5 +1,5 @@
/**
* omi v3.0.4 http://omijs.org
* omi v3.0.5 http://omijs.org
* Omi === Preact + Scoped CSS + Store System + Native Support in 3kb javascript.
* By dntzhang https://github.com/dntzhang
* Github: https://github.com/AlloyTeam/omi
@ -39,7 +39,9 @@
isWeb: true,
staticStyleRendered: false,
doc: typeof document === 'object' ? document : null,
root: getGlobal()
root: getGlobal(),
//styleCache :[{ctor:ctor,ctorName:ctorName,style:style}]
styleCache: []
//componentChange(component, element) { },
/** If `true`, `prop` changes trigger synchronous component updates.
* @name syncComponentUpdates
@ -1020,6 +1022,25 @@
}
}
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]
@ -1107,13 +1128,13 @@
if (!skip) {
rendered = component.render(props, state, context);
if (component.style) {
addScopedAttr(rendered, component.style(), '_style_' + component._id, component);
}
//don't rerender
if (component.staticStyle) {
addScopedAttrStatic(rendered, component.staticStyle(), '_style_' + component.constructor.name);
addScopedAttrStatic(rendered, component.staticStyle(), '_style_' + getCtorName(component.constructor));
}
if (component.style) {
addScopedAttr(rendered, component.style(), '_style_' + component._id, component);
}
// context to pass to the child, can be updated via (grand-)parent component
@ -1291,9 +1312,9 @@
if (component.__ref) component.__ref(null);
}
var id = 0;
var id$1 = 0;
function getId() {
return id++;
return id$1++;
}
/** Base Component class.
* Provides `setState()` and `forceUpdate()`, which trigger rendering.
@ -1463,7 +1484,7 @@
instances: instances
};
options.root.Omi.version = '3.0.4';
options.root.Omi.version = '3.0.5';
var Omi = {
h: h,

2
dist/omi.dev.js.map vendored

File diff suppressed because one or more lines are too long

41
dist/omi.esm.js vendored
View File

@ -1,5 +1,5 @@
/**
* omi v3.0.4 http://omijs.org
* omi v3.0.5 http://omijs.org
* Omi === Preact + Scoped CSS + Store System + Native Support in 3kb javascript.
* By dntzhang https://github.com/dntzhang
* Github: https://github.com/AlloyTeam/omi
@ -36,7 +36,9 @@ var options = {
isWeb: true,
staticStyleRendered: false,
doc: typeof document === 'object' ? document : null,
root: getGlobal()
root: getGlobal(),
//styleCache :[{ctor:ctor,ctorName:ctorName,style:style}]
styleCache: []
//componentChange(component, element) { },
/** If `true`, `prop` changes trigger synchronous component updates.
* @name syncComponentUpdates
@ -1017,6 +1019,25 @@ 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]
@ -1104,13 +1125,13 @@ function renderComponent(component, opts, mountAll, isChild) {
if (!skip) {
rendered = component.render(props, state, context);
if (component.style) {
addScopedAttr(rendered, component.style(), '_style_' + component._id, component);
}
//don't rerender
if (component.staticStyle) {
addScopedAttrStatic(rendered, component.staticStyle(), '_style_' + component.constructor.name);
addScopedAttrStatic(rendered, component.staticStyle(), '_style_' + getCtorName(component.constructor));
}
if (component.style) {
addScopedAttr(rendered, component.style(), '_style_' + component._id, component);
}
// context to pass to the child, can be updated via (grand-)parent component
@ -1288,9 +1309,9 @@ function unmountComponent(component) {
if (component.__ref) component.__ref(null);
}
var id = 0;
var id$1 = 0;
function getId() {
return id++;
return id$1++;
}
/** Base Component class.
* Provides `setState()` and `forceUpdate()`, which trigger rendering.
@ -1460,7 +1481,7 @@ options.root.Omi = {
instances: instances
};
options.root.Omi.version = '3.0.4';
options.root.Omi.version = '3.0.5';
var omi = {
h: h,

2
dist/omi.esm.js.map vendored

File diff suppressed because one or more lines are too long

23
dist/omi.js vendored
View File

@ -342,6 +342,19 @@
});
}
}
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;
@ -377,8 +390,8 @@
component.__p = component.__s = component.__c = component.__b = null;
if (!skip) {
rendered = component.render(props, state, context);
if (component.staticStyle) addScopedAttrStatic(rendered, component.staticStyle(), '_style_' + getCtorName(component.constructor));
if (component.style) addScopedAttr(rendered, component.style(), '_style_' + component.s, component);
if (component.staticStyle) addScopedAttrStatic(rendered, component.staticStyle(), '_style_' + component.constructor.name);
if (component.getChildContext) context = extend(extend({}, context), component.getChildContext());
var toUnmount, base, childComponent = rendered && rendered.nodeName;
if ('function' == typeof childComponent) {
@ -473,7 +486,7 @@
if (component.__r) component.__r(null);
}
function getId() {
return id++;
return id$1++;
}
function Component(props, context) {
this.context = context;
@ -527,7 +540,8 @@
}();
}
return global;
}()
}(),
styleCache: []
};
var stack = [];
var EMPTY_CHILDREN = [];
@ -666,6 +680,7 @@
var hydrating = !1;
var components = {};
var id = 0;
var id$1 = 0;
extend(Component.prototype, {
setState: function(state, callback) {
var s = this.state;
@ -695,7 +710,7 @@
options: options,
instances: instances
};
options.root.Omi.version = '3.0.4';
options.root.Omi.version = '3.0.5';
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.4",
"version": "3.0.5",
"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.4';
options.root.Omi.version = '3.0.5';
export default {
h,

View File

@ -26,7 +26,9 @@ export default {
isWeb: true,
staticStyleRendered: false,
doc: typeof document === 'object' ? document : null,
root: getGlobal()
root: getGlobal(),
//styleCache :[{ctor:ctor,ctorName:ctorName,style:style}]
styleCache: []
//componentChange(component, element) { },
/** If `true`, `prop` changes trigger synchronous component updates.
* @name syncComponentUpdates

View File

@ -8,6 +8,27 @@ 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;
}
/** Set a component's `props` (generally derived from JSX attributes).
* @param {Object} props
* @param {Object} [opts]
@ -99,13 +120,14 @@ export function renderComponent(component, opts, mountAll, isChild) {
if (!skip) {
rendered = component.render(props, state, context);
if (component.style){
addScopedAttr(rendered,component.style(),'_style_'+component._id,component);
}
//don't rerender
if (component.staticStyle){
addScopedAttrStatic(rendered,component.staticStyle(),'_style_'+component.constructor.name);
addScopedAttrStatic(rendered,component.staticStyle(),'_style_' + getCtorName(component.constructor));
}
if (component.style){
addScopedAttr(rendered,component.style(),'_style_'+component._id,component);
}
// context to pass to the child, can be updated via (grand-)parent component

View File

@ -144,7 +144,7 @@ describe('Components', () => {
render(<C2 />, scratch);
expect(scratch.innerHTML).to.equal('<div _style_c2=""></div>');
expect(scratch.innerHTML).to.equal('<div _style_static_0=""></div>');
});
it('should render components with scoped attr', () => {
@ -166,7 +166,7 @@ describe('Components', () => {
render(<C2 />, scratch);
expect(scratch.innerHTML).to.equal('<div _style_15="" _style_c2=""></div>');
expect(scratch.innerHTML).to.equal('<div _style_static_1="" _style_15=""></div>');
});
it('should render components with store', () => {