-
-
0需求: 退出登录 分析: 类似【二次开发笔记(二)】中的登录逻辑,scratch-gui/src/components/menu-bar/menu-bar.jsx 已经提供了 onLogOut 接口,直接在 src/containers/gui.jsx 中定义 onLogout 处理逻辑即可。 实现: // src/containers/gui.jsx ... import {setSession} from '../reducers/session'; ... return (<GUIComponent onLogOut={onLogout} ...>{children}</GUIComponent> ); ... GUI.propTypes = { ... onLogout: PropTypes.func } ... const mapDispatchToProps = dispatch => ({ ... onLogout: () => dispatch(setSession(null)) });
-
0需求: 实现 scratch-gui 登录后,每次刷新页面(F5 或强制刷新)都需要重新登录。 分析: redux 的实质就是: 状态管理(全局变量管理)。刷新页面相当于重新 “实例化” window (document ?)“挂载的”变量自然会在父级对象销毁时丢失。所以要在父级对象销毁(页面刷新)前保存,重建父级对象(页面刷新)后恢复。 实现: src/lib/app-state-hoc.jsx ... const loadSession = () => { try { // TODO 兼容不支持 localStorage 的情况 const serializedSession = localStorage.getItem('s
-
0需求: sb3 自动演示 分析: scratch-vm 源码 constructor 中添加了非常多的监听器(this.runtime.on(Runtime.SCRIPT_GLOW_OFF, ...),底层依赖 nodejs 的 events 实现。言外之意就是 vm 可以直接使用 vm.on(事件名称, callback) 添加监听器。而且 Runtime 里已非常语义化定义了 PROJECT_START、PROJECT_RUN_START、PROJECT_RUN_STOP 等事件 结果: const vm = new ScratchVM(); vm.on('PROJECT_RUN_STOP', () => redirect_to_next)
-
0