setting.js 674 B

123456789101112131415161718192021222324252627
  1. import defaultSettings from '../../config/defaultSettings';
  2. const updateColorWeak = (colorWeak) => {
  3. const root = document.getElementById('root');
  4. if (root) {
  5. root.className = colorWeak ? 'colorWeak' : '';
  6. }
  7. };
  8. const SettingModel = {
  9. namespace: 'settings',
  10. state: defaultSettings,
  11. reducers: {
  12. changeSetting(state = defaultSettings, { payload }) {
  13. const { colorWeak, contentWidth } = payload;
  14. if (state.contentWidth !== contentWidth && window.dispatchEvent) {
  15. window.dispatchEvent(new Event('resize'));
  16. }
  17. updateColorWeak(!!colorWeak);
  18. return { ...state, ...payload };
  19. },
  20. },
  21. };
  22. export default SettingModel;