chore: rename useComponentState to useStoreState

This commit is contained in:
Haishan 2018-12-20 23:35:17 +08:00
parent 690beda0b9
commit 00d90f49de
10 changed files with 21 additions and 21 deletions

View file

@ -1,5 +1,5 @@
import React, { useState, useEffect, useRef } from 'react';
import { useComponentState, useActions } from 'm/store';
import { useStoreState, useActions } from 'm/store';
import Input from 'c/Input';
import Button from 'c/Button';
@ -13,7 +13,7 @@ const mapStateToProps = s => ({
});
function APIConfig2() {
const { apiConfig } = useComponentState(mapStateToProps);
const { apiConfig } = useStoreState(mapStateToProps);
const [hostname, setHostname] = useState(apiConfig.hostname);
const [port, setPort] = useState(apiConfig.port);
const [secret, setSecret] = useState(apiConfig.secret);

View file

@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { useActions, useComponentState } from 'm/store';
import { useActions, useStoreState } from 'm/store';
import Modal from 'c/Modal';
import APIConfig from 'c/APIConfig';
@ -19,7 +19,7 @@ const actions = {
};
export default function APIDiscovery() {
const { modals } = useComponentState(mapStateToProps);
const { modals } = useStoreState(mapStateToProps);
const { closeModal, fetchConfigs } = useActions(actions);
useEffect(() => {
fetchConfigs();

View file

@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { useComponentState, useActions } from 'm/store';
import { useStoreState, useActions } from 'm/store';
import { getConfigs, fetchConfigs, updateConfigs } from 'd/configs';
@ -57,7 +57,7 @@ const mapStateToProps = s => ({ configs: getConfigs(s) });
export default function ConfigContainer() {
const { fetchConfigs } = useActions(actions);
const { configs } = useComponentState(mapStateToProps);
const { configs } = useStoreState(mapStateToProps);
useEffect(() => {
fetchConfigs();
}, []);

View file

@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import { useComponentState } from 'm/store';
import { useStoreState } from 'm/store';
import { getClashAPIConfig } from 'd/app';
import Icon from 'c/Icon';
@ -45,7 +45,7 @@ LogLine.propTypes = {
export default function Logs() {
const [logs, setLogs] = useState([]);
const { hostname, port, secret } = useComponentState(getClashAPIConfig);
const { hostname, port, secret } = useStoreState(getClashAPIConfig);
useEffect(
() => {

View file

@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { useActions, useComponentState } from 'm/store';
import { useActions, useStoreState } from 'm/store';
import ContentHeader from 'c/ContentHeader';
import ProxyGroup from 'c/ProxyGroup';
@ -29,7 +29,7 @@ export default function Proxies() {
useEffect(() => {
fetchProxies();
}, []);
const { groupNames } = useComponentState(mapStateToProps);
const { groupNames } = useStoreState(mapStateToProps);
return (
<div>

View file

@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { useComponentState } from 'm/store';
import { useStoreState } from 'm/store';
import Icon from 'c/Icon';
import ProxyLatency from 'c/ProxyLatency';
@ -41,7 +41,7 @@ const mapStateToProps = s => {
};
function Proxy({ now, name }) {
const { proxies, delay } = useComponentState(mapStateToProps);
const { proxies, delay } = useStoreState(mapStateToProps);
// const { name, proxies, delay, now } = this.props;
const latency = delay[name];

View file

@ -1,6 +1,6 @@
import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import { useActions, useComponentState } from 'm/store';
import { useActions, useStoreState } from 'm/store';
import Proxy from 'c/Proxy';
@ -15,7 +15,7 @@ const mapStateToProps = s => ({
// should move this to sth like constants.js
// const userProxyTypes = ['Shadowsocks', 'Vmess', 'Socks5'];
export default function ProxyGroup2({ name }) {
const { proxies } = useComponentState(mapStateToProps);
const { proxies } = useStoreState(mapStateToProps);
const actions = useActions({ switchProxy });
const group = proxies[name];
const { all, now } = group;

View file

@ -2,7 +2,7 @@ import React, { useEffect } from 'react';
import prettyBytes from 'm/pretty-bytes';
import { fetchData } from '../api/traffic';
import { unstable_createResource as createResource } from 'react-cache';
import { useComponentState } from 'm/store';
import { useStoreState } from 'm/store';
import { getClashAPIConfig, getTheme } from 'd/app';
// const delay = ms => new Promise(r => setTimeout(r, ms));
@ -139,8 +139,8 @@ const chartWrapperStyle = {
export default function TrafficChart() {
const Chart = chartJSResource.read();
const { hostname, port, secret } = useComponentState(getClashAPIConfig);
const theme = useComponentState(getTheme);
const { hostname, port, secret } = useStoreState(getClashAPIConfig);
const theme = useStoreState(getTheme);
useEffect(
() => {

View file

@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react';
import prettyBytes from 'm/pretty-bytes';
import { useComponentState } from 'm/store';
import { useStoreState } from 'm/store';
import { getClashAPIConfig } from 'd/app';
import { fetchData } from '../api/traffic';
@ -25,7 +25,7 @@ export default function TrafficNow() {
function useSpeed() {
const [speed, setSpeed] = useState({ upStr: '0 B/s', downStr: '0 B/s' });
const { hostname, port, secret } = useComponentState(getClashAPIConfig);
const { hostname, port, secret } = useStoreState(getClashAPIConfig);
useEffect(
() => {
return fetchData({

View file

@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { bindActionCreators } from 'redux';
import shallowEqual from './shallowEqual';
export const StoreContext = createContext(null);
const StoreContext = createContext(null);
export function Provider({ store, children }) {
return (
@ -28,7 +28,7 @@ export function useActions(actions) {
return bindActionCreators(a, dispatch);
}
export function useComponentState(selector) {
export function useStoreState(selector) {
const store = useStore();
const initialMappedState = selector(store.getState());
const [compState, setCompState] = useState(initialMappedState);