Merge branch 'feat/autoRepaintNode' into release/1.0.16-beta

This commit is contained in:
liujuping 2022-11-07 11:50:25 +08:00
commit 600b468ef2
5 changed files with 30 additions and 25 deletions

View File

@ -203,12 +203,9 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
}; };
}); });
transactionManager.onStartTransaction(() => { transactionManager.onStartTransaction(() => {
this.project.currentDocument?.history?.sleep();
this.stopAutoRepaintNode(); this.stopAutoRepaintNode();
}, TransitionType.REPAINT); }, TransitionType.REPAINT);
transactionManager.onEndTransaction(() => { transactionManager.onEndTransaction(() => {
this.project.currentDocument?.history?.wakeup();
this.project.currentDocument?.history?.savePoint();
this.rerender(); this.rerender();
this.enableAutoRepaintNode(); this.enableAutoRepaintNode();
}, TransitionType.REPAINT); }, TransitionType.REPAINT);

View File

@ -1,5 +1,5 @@
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
import { autorun, reaction, mobx, untracked, globalContext, Editor } from '@alilc/lowcode-editor-core'; import { reaction, untracked, globalContext, Editor } from '@alilc/lowcode-editor-core';
import { NodeSchema } from '@alilc/lowcode-types'; import { NodeSchema } from '@alilc/lowcode-types';
import { History as ShellHistory } from '@alilc/lowcode-shell'; import { History as ShellHistory } from '@alilc/lowcode-shell';
@ -40,24 +40,22 @@ export class History<T = NodeSchema> {
if (this.asleep) return null; if (this.asleep) return null;
return dataFn(); return dataFn();
}, (data: T) => { }, (data: T) => {
if (this.asleep) return;
untracked(() => { untracked(() => {
const log = this.currentSerialization.serialize(data); const log = this.currentSerialization.serialize(data);
if (this.session.isActive()) { if (this.session.isActive()) {
this.session.log(log); this.session.log(log);
} else { } else {
this.session.end(); this.session.end();
const lastState = this.getState(); const lastState = this.getState();
const cursor = this.session.cursor + 1; const cursor = this.session.cursor + 1;
const session = new Session(cursor, log, this.timeGap); const session = new Session(cursor, log, this.timeGap);
this.session = session; this.session = session;
this.records.splice(cursor, this.records.length - cursor, session); this.records.splice(cursor, this.records.length - cursor, session);
const currentState = this.getState(); const currentState = this.getState();
if (currentState !== lastState) { if (currentState !== lastState) {
this.emitter.emit('statechange', currentState); this.emitter.emit('statechange', currentState);
}
} }
// } }
}); });
}, { fireImmediately: true }); }, { fireImmediately: true });
} }

View File

@ -229,11 +229,11 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
this.recordTime(); this.recordTime();
} }
get defaultState() { getDefaultState(nextProps: any) {
const { const {
hidden = false, hidden = false,
condition = true, condition = true,
} = this.leaf?.export?.(TransformStage.Render) || {}; } = nextProps.__inner__ || {};
return { return {
nodeChildren: null, nodeChildren: null,
childrenInState: false, childrenInState: false,
@ -257,7 +257,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
let cacheState = cache.state.get(componentCacheId); let cacheState = cache.state.get(componentCacheId);
if (!cacheState || cacheState.__tag !== props.__tag) { if (!cacheState || cacheState.__tag !== props.__tag) {
cacheState = this.defaultState; cacheState = this.getDefaultState(props);
} }
this.state = cacheState; this.state = cacheState;
@ -393,7 +393,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
const { const {
visible, visible,
...resetState ...resetState
} = this.defaultState; } = this.getDefaultState(nextProps);
this.setState(resetState); this.setState(resetState);
} }
@ -562,6 +562,8 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, {
ref: forwardedRef, ref: forwardedRef,
}; };
delete compProps.__inner__;
return engine.createElement(Comp, compProps, this.hasChildren ? this.children : null); return engine.createElement(Comp, compProps, this.hasChildren ? this.children : null);
} }
} }

View File

@ -670,7 +670,14 @@ export default function baseRendererFactory(): IBaseRenderComponent {
} }
} }
} }
return renderComp({ ...props, ...otherProps }); return renderComp({
...props,
...otherProps,
__inner__: {
hidden: schema.hidden,
condition,
},
});
} catch (e) { } catch (e) {
return engine.createElement(engine.getFaultComponent(), { return engine.createElement(engine.getFaultComponent(), {
error: e, error: e,

View File

@ -1,4 +1,5 @@
import { TransitionType } from '@alilc/lowcode-types'; import { TransitionType } from '@alilc/lowcode-types';
import { transaction } from 'mobx';
import EventEmitter from 'events'; import EventEmitter from 'events';
class TransactionManager { class TransactionManager {
@ -6,7 +7,7 @@ class TransactionManager {
startTransaction = (fn: () => void, type: TransitionType = TransitionType.REPAINT): void => { startTransaction = (fn: () => void, type: TransitionType = TransitionType.REPAINT): void => {
this.emitter.emit(`[${type}]startTransaction`); this.emitter.emit(`[${type}]startTransaction`);
fn(); transaction(fn);
this.emitter.emit(`[${type}]endTransaction`); this.emitter.emit(`[${type}]endTransaction`);
}; };