Browse Source

Pull request #3450: KERNEL-14316 chore: Fix ES6 化

Merge in VISUAL/fineui from ~TREECAT/fineui:es6 to es6

* commit 'f1870a58e4e74549352eb2fd2e6f3f4773ab239f':
  KERNEL-14316 chore: Fix ES6 化
es6
treecat-罗群 2 years ago
parent
commit
b9bea5ca87
  1. 2
      src/core/0.foundation.js
  2. 2
      src/core/2.base.js
  3. 6
      src/core/conflict.js
  4. 6
      src/core/index.js
  5. 231
      src/fix/fix.compact.js
  6. 1546
      src/fix/fix.js
  7. 2
      src/fix/index.js
  8. 3
      src/index.js
  9. 12
      src/polyfill/console.js
  10. 1
      src/polyfill/index.js

2
src/core/0.foundation.js vendored

@ -1,7 +1,5 @@
/** /**
* Created by richie on 15/7/8. * Created by richie on 15/7/8.
*
* 初始化 _global 对象为什么不是 globalThis
*/ */
let _global = undefined; let _global = undefined;
if (typeof window !== "undefined") { if (typeof window !== "undefined") {

2
src/core/2.base.js

@ -1634,5 +1634,3 @@ export function getTime() {
return dt.getTime(); return dt.getTime();
} }
export const lodashUtils = BI._;

6
src/core/conflict.js

@ -1,6 +0,0 @@
// if (!_global.$ && !_global.jQuery) {
// _global.jQuery = _global.$ = BI.jQuery;
// }
// if (!_global._) {
// _global._ = BI._;
// }

6
src/core/index.js

@ -35,3 +35,9 @@ export * from "./utils";
export { shortcut, provider } from "./decorator"; export { shortcut, provider } from "./decorator";
import _ from "./1.lodash";
export {
_
};

231
src/fix/fix.compact.js

@ -0,0 +1,231 @@
import {
_,
isArray,
each,
isKey,
isPlainObject,
extend,
isFunction,
Widget,
Providers
} from "@/core";
import { Fix } from "./fix";
function initWatch(vm, watch) {
vm._watchers || (vm._watchers = []);
for (const key in watch) {
const handler = watch[key];
if (isArray(handler)) {
for (let i = 0; i < handler.length; i++) {
vm._watchers.push(createWatcher(vm, key, handler[i]));
}
} else {
vm._watchers.push(createWatcher(vm, key, handler));
}
}
each(vm.$watchDelayCallbacks, (i, watchDelayCallback) => {
let innerWatch = watchDelayCallback[0];
const innerHandler = watchDelayCallback[1];
if (isKey(innerWatch)) {
const key = innerWatch;
innerWatch = {};
innerWatch[key] = innerHandler;
}
for (const key in innerWatch) {
const handler = innerWatch[key];
if (isArray(handler)) {
for (let i = 0; i < handler.length; i++) {
vm._watchers.push(createWatcher(vm, key, handler[i]));
}
} else {
vm._watchers.push(createWatcher(vm, key, handler));
}
}
});
}
function createWatcher(vm, keyOrFn, cb, options) {
if (isPlainObject(cb)) {
options = cb;
cb = cb.handler;
}
options = options || {};
return Fix.watch(
vm.model,
keyOrFn,
_.bind(cb, vm),
extend(options, {
store: vm.store
})
);
}
let target = null;
const targetStack = [];
function pushTarget(_target) {
if (target) targetStack.push(target);
Fix.Model.target = target = _target;
}
function popTarget() {
Fix.Model.target = target = targetStack.pop();
}
export const Model = Fix.Model;
const oldWatch = Fix.watch;
Fix.watch = function (model, expOrFn, cb, options) {
if (isPlainObject(cb)) {
options = cb;
cb = cb.handler;
}
if (typeof cb === "string") {
cb = model[cb];
}
return oldWatch.call(
this,
model,
expOrFn,
function () {
options && options.store && pushTarget(options.store);
let res;
try {
res = cb.apply(this, arguments);
} catch (e) {
console.error(e);
}
options && options.store && popTarget();
return res;
},
options
);
};
Widget.findStore = function findStore(widget) {
if (target != null) {
return target;
}
widget = widget || Widget.context;
let p = widget;
while (p) {
if (p instanceof Fix.Model || p.store || p.__cacheStore) {
break;
}
p = p._parent || (p.options && p.options.element) || p._context;
}
if (p) {
if (p instanceof Fix.Model) {
return (widget.__cacheStore = p);
}
widget.__cacheStore = p.store || p.__cacheStore;
return p.__cacheStore || p.store;
}
};
function createStore() {
let needPop = false;
const workerMode =
Providers.getProvider("bi.provider.system").getWorkerMode();
if (workerMode && this._worker) {
return;
}
if (this.store) {
pushTarget(this.store);
return true;
}
if (this._store || this.options._store) {
const store = Widget.findStore(
this.options.context ||
this._parent ||
this.options.element ||
this._context
);
if (store) {
pushTarget(store);
needPop = true;
}
this.store = (this._store || this.options._store).call(this);
this.store && (this.store._widget = this);
needPop && popTarget();
needPop = false;
pushTarget(this.store);
if (this.store instanceof Fix.Model) {
this.model = this.store.model;
} else {
this.model = this.store;
}
needPop = true;
}
return needPop;
}
const _init = Widget.prototype._init;
Widget.prototype._init = function () {
const needPop = createStore.call(this);
try {
_init.apply(this, arguments);
} catch (e) {
console.error(e);
}
needPop && popTarget();
};
const __initWatch = Widget.prototype.__initWatch;
Widget.prototype.__initWatch = function () {
__initWatch.apply(this, arguments);
const workerMode =
Providers.getProvider("bi.provider.system").getWorkerMode();
if (workerMode && this._worker) {
return;
}
if (this._store) {
initWatch(this, this.watch);
}
};
const unMount = Widget.prototype.__destroy;
Widget.prototype.__destroy = function () {
try {
unMount.apply(this, arguments);
} catch (e) {
console.error(e);
}
this.store && isFunction(this.store.destroy) && this.store.destroy();
each(this._watchers, (i, unwatches) => {
unwatches = isArray(unwatches) ? unwatches : [unwatches];
each(unwatches, (j, unwatch) => {
unwatch();
});
});
this._watchers && (this._watchers = []);
if (this.store) {
this.store._parent && (this.store._parent = null);
this.store._widget && (this.store._widget = null);
this.store = null;
}
delete this.__cacheStore;
};
_.each(["_render", "__afterRender", "_mount", "__afterMount"], (name) => {
const old = Widget.prototype[name];
old &&
(Widget.prototype[name] = function () {
this.store && pushTarget(this.store);
let res;
try {
res = old.apply(this, arguments);
} catch (e) {
console.error(e);
}
this.store && popTarget();
return res;
});
});

1546
src/fix/fix.js

File diff suppressed because it is too large Load Diff

2
src/fix/index.js

@ -0,0 +1,2 @@
export * from "./fix";
export * from "./fix.compact";

3
src/index.js

@ -1,5 +1,8 @@
import "./polyfill";
export * from "./core"; export * from "./core";
export * from "./base"; export * from "./base";
export * from "./case"; export * from "./case";
export * from "./widget"; export * from "./widget";
export * from "./component"; export * from "./component";
export * from "./fix";

12
src/polyfill/console.js

@ -1,12 +0,0 @@
/**
* 特殊情况
* Created by wang on 15/6/23.
*/
// 解决console未定义问题 guy
_global.console = _global.console || (function () {
var c = {};
c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
= c.clear = c.exception = c.trace = c.assert = function () {
};
return c;
})();

1
src/polyfill/index.js

@ -1,4 +1,3 @@
export * from "./console";
export * from "./event"; export * from "./event";
export * from "./number"; export * from "./number";
export * from "./sort"; export * from "./sort";
Loading…
Cancel
Save