在调用操作后嵌套Redux状态

时间:2016-07-19 06:49:46

标签: reactjs redux

我有一个小问题:

我的减速机

Name:       kube-dns-v18-u7jgt
Namespace:  default
Node:       centos-cjw-minion1/10.139.4.195
Start Time: Mon, 18 Jul 2016 19:31:48 +0800
Labels:     k8s-app=kube-dns,kubernetes.io/cluster-service=true,version=v18
Status:     Running
IP:     172.17.0.4
Controllers:    ReplicationController/kube-dns-v18
Containers:
  kubedns:
    Container ID:   docker://5f97e1d7185e327ac3cd5415c79b1b51da1987d8946fb243ee1758cdc4d53d29
    Image:      iaasfree/kubedns-amd64:1.5
    Image ID:       docker://sha256:a1490b272781a9921ba216778e741943e9b866114dae7e7e8980daebbc5ba7ed
    Ports:      10053/UDP, 10053/TCP
    Args:
      --domain=cluster.local.
      --dns-port=10053
    QoS Tier:
      memory:   Burstable
      cpu:  Guaranteed
    Limits:
      cpu:  100m
      memory:   200Mi
    Requests:
      cpu:      100m
      memory:       100Mi
    State:      Running
      Started:      Mon, 18 Jul 2016 19:36:02 +0800
    Last State:     Terminated
      Reason:       Error
      Exit Code:    255
      Started:      Mon, 18 Jul 2016 19:34:52 +0800
      Finished:     Mon, 18 Jul 2016 19:35:59 +0800
    Ready:      False
    Restart Count:  3
    Liveness:       http-get http://:8080/healthz delay=60s timeout=5s period=10s #success=1 #failure=5
    Readiness:      http-get http://:8081/readiness delay=30s timeout=5s period=10s #success=1 #failure=3
    Environment Variables:
  dnsmasq:
    Container ID:   docker://75ef5bc18dfe196438956c42f64a2e2d6fd408329408704f32534ce7b9252663
    Image:      iaasfree/kube-dnsmasq-amd64:1.3
    Image ID:       docker://sha256:8cb0646c9e984cf510ca70704154bee2f2c51cfb2e776f4357c52c1d17c2b741
    Ports:      53/UDP, 53/TCP
    Args:
      --cache-size=1000
      --no-resolv
      --server=127.0.0.1#10053
    QoS Tier:
      cpu:      BestEffort
      memory:       BestEffort
    State:      Running
      Started:      Mon, 18 Jul 2016 19:31:55 +0800
    Ready:      True
    Restart Count:  0
    Environment Variables:
  healthz:
    Container ID:   docker://e11626508ecd5b2cfae3e1eaa3284d75dae4160c113d7f28ce97cbd0185f032d
    Image:      iaasfree/exechealthz-amd64:1.0
    Image ID:       docker://sha256:f3b98b5b347af3254c82e3a0090cd324daf703970f3bb62ba8005020ddf5a156
    Port:       8080/TCP
    Args:
      -cmd=nslookup kubernetes.default.svc.cluster.local 127.0.0.1 >/dev/null && nslookup kubernetes.default.svc.cluster.local 127.0.0.1:10053 >/dev/null
      -port=8080
      -quiet
    QoS Tier:
      cpu:  Guaranteed
      memory:   Guaranteed
    Limits:
      memory:   20Mi
      cpu:  10m
    Requests:
      cpu:      10m
      memory:       20Mi
    State:      Running
      Started:      Mon, 18 Jul 2016 19:32:12 +0800
    Ready:      True
    Restart Count:  0
    Environment Variables:
Conditions:
  Type      Status
  Ready     False 
No volumes.
Events:
  FirstSeen LastSeen    Count   From                SubobjectPath           Type        Reason      Message
  --------- --------    -----   ----                -------------           --------    ------      -------
  5m        5m      1   {default-scheduler }                        Normal      Scheduled   Successfully assigned kube-dns-v18-u7jgt to centos-cjw-minion1
  4m        4m      1   {kubelet centos-cjw-minion1}    spec.containers{kubedns}    Normal      Created     Created container with docker id 5814904f6e09
  4m        4m      1   {kubelet centos-cjw-minion1}    spec.containers{dnsmasq}    Normal      Pulled      Container image "iaasfree/kube-dnsmasq-amd64:1.3" already present on machine
  4m        4m      1   {kubelet centos-cjw-minion1}    spec.containers{kubedns}    Normal      Started     Started container with docker id 5814904f6e09
  4m        4m      1   {kubelet centos-cjw-minion1}    spec.containers{dnsmasq}    Normal      Created     Created container with docker id 75ef5bc18dfe
  4m        4m      1   {kubelet centos-cjw-minion1}    spec.containers{dnsmasq}    Normal      Started     Started container with docker id 75ef5bc18dfe
  4m        4m      1   {kubelet centos-cjw-minion1}    spec.containers{healthz}    Normal      Pulled      Container image "iaasfree/exechealthz-amd64:1.0" already present on machine
  4m        4m      1   {kubelet centos-cjw-minion1}    spec.containers{healthz}    Normal      Created     Created container with docker id e11626508ecd
  4m        4m      1   {kubelet centos-cjw-minion1}    spec.containers{healthz}    Normal      Started     Started container with docker id e11626508ecd
  3m        3m      1   {kubelet centos-cjw-minion1}    spec.containers{kubedns}    Normal      Killing     Killing container with docker id 5814904f6e09: pod "kube-dns-v18-u7jgt_default(370b6791-4cdb-11e6-80f0-fa163ebb45ec)" container "kubedns" is unhealthy, it will be killed and re-created.
</code>

After execu statment “kubectl logs kube-dns-v18-yhk41 -c kubedns” showed bellow:

<code>I0719 06:43:41.335795       1 dns.go:172] Ignoring error while waiting for service default/kubernetes: serializer for text/html; charset=utf-8 doesn't exist. Sleeping 1s before retrying.
E0719 06:43:41.335928       1 reflector.go:216] pkg/dns/dns.go:155: Failed to list *api.Service: serializer for text/html; charset=utf-8 doesn't exist
E0719 06:43:41.533705       1 reflector.go:216] pkg/dns/dns.go:154: Failed to list *api.Endpoints: serializer for text/html; charset=utf-8 doesn't exist
I0719 06:43:41.534017       1 dns.go:439] Received DNS Request:kubernetes.default.svc.cluster.local., exact:false
I0719 06:43:41.534048       1 dns.go:539] records:[], retval:[], path:[local cluster svc default kubernetes]
I0719 06:43:42.336756       1 dns.go:172] Ignoring error while waiting for service default/kubernetes: serializer for text/html; charset=utf-8 doesn't exist. Sleeping 1s before retrying.
E0719 06:43:42.336893       1 reflector.go:216] pkg/dns/dns.go:155: Failed to list *api.Service: serializer for text/html; charset=utf-8 doesn't exist
E0719 06:43:42.534553       1 reflector.go:216] pkg/dns/dns.go:154: Failed to list *api.Endpoints: serializer for text/html; charset=utf-8 doesn't exist

在我的主文件中,我有一个行动呼吁

const initialObject = {
    counter: 0,
    messages: []
};

function message(state = initialObject, action) {
    switch(action.type) {

        case actions.ADD_MESSAGE:
            return state; // do nothing just return the same state, expect to equal initialObject
        default:
            return state;
    }
}

const testApp = combineReducers({
   message
});

问题是,我在“订阅”

之后在控制台中看到的对象

enter image description here

它是嵌套的...任何想法为什么?这仅在动作调用后发生。

1 个答案:

答案 0 :(得分:1)

是的,这是因为这一行

const testApp = combineReducers({
   message
});

在ES6中,这个

{ message }

与此相同:

{ message: message }

所以你的状态是一个带钥匙的对象。在此示例中,它只有一个键:message

来自自述文件:https://www.github.com/reactjs/redux/blob/master/docs/basics/Reducers.md

  

所有combineReducers()都会生成一个函数,该函数使用根据其键选择的状态切片调用reducers,并将其结果再次组合到单个对象中。这不是魔术。