我有一个负责打开/关闭窗口的人,我试图打开时随机显示三个礼物之一。虽然没有进展,但我该怎么办。
我知道我需要通过state.random来执行此操作,但现在我不知道如何操作。显然我是完全金发的))))
//开始打开框
var TOGGLE_BOX = '[GiftBox] Toggle';
var toggleBox = function () {
return { type: TOGGLE_BOX };
};
//REDUCERS (Update)
var DEFAULT = { open: false, wasOpen: false };
var reducer = function (state, action) {
if (state === void 0) {state = DEFAULT;}
switch (action.type) {
case TOGGLE_BOX:{
return {
open: state.open ? false : true,
wasOpen: state.open };
}
default:return state;}
};
var store = Redux.createStore(reducer, DEFAULT);
var mapStateToProps = function (state) {
return { open: state.open, wasOpen: state.wasOpen };
};
var mapDispatchToProps = function (dispatch) {
return { dispatch: dispatch };
};
var cGiftBox = function (_a) {
var wasOpen = _a.wasOpen,open = _a.open,dispatch = _a.dispatch;
return React.createElement("div", { className: "floor" },
React.createElement("div", { className: "box" },
open ?
React.createElement("button", { className: "heart-gift", }, "gift1") :
React.createElement(React.Fragment, null),
React.createElement("div", { className: open ?
'lid open' :
wasOpen ?
'lid close' :
'lid', onClick: function (e) {return dispatch(toggleBox());} },
React.createElement("div", { className: "qcube" }, open ? '!' : '?'),
React.createElement("div", { className: "face ltop" }),
React.createElement("div", { className: "face lleft" }),
React.createElement("div", { className: "face lright" })),
React.createElement("div", { className: "face top" }),
React.createElement("div", { className: "face left" }),
React.createElement("div", { className: "face right" }),
));
};
// connect and render
var Provider = ReactRedux.Provider,connect = ReactRedux.connect;
var GiftBox = connect(mapStateToProps, mapDispatchToProps)(cGiftBox);
ReactDOM.render(React.createElement(Provider, { store: store },
React.createElement(GiftBox, null)), document.getElementById('root'));