映射归一化的redux状态时呈现

时间:2019-01-16 02:19:17

标签: reactjs redux react-redux immutable.js

我正在使用规范化的状态模式,并且需要在状态树的一部分中呈现所有对象,因此我尝试在它们上进行映射并呈现。但是索引与对象一起保留渲染。为什么会这样?

我的状态受动作影响:

import sys
from Bio import AlignIO
from Bio import SeqIO
from Bio.Seq import Seq
import time
start_time = time.time()

databasefile = sys.argv[1]
queryfile = sys.argv[2]

file_hits = "./" + sys.argv[2].split("_protein")[0] + "_ZeNovo_hits_v1.txt"
file_report = "./" + sys.argv[2].split("_protein")[0] + "_ZeNovo_report_v1.txt"
format = "fasta"
output_file = open(file_hits, 'w')
output_file_2 = open(file_report,'w')
sequences_dict = {}

output_file.write("{}\t{}\n".format("protein_query", "hits"))
for record in SeqIO.parse(databasefile, format):
    sequences_dict[record.description] = str(record.seq)
print("processed database in --- {:.3f} seconds ---".format(time.time() - start_time))

processed_counter = 0
for record in SeqIO.parse(queryfile, format):
    query_seq = str(record.seq)
    count = 0
    output_file.write("{}\t".format(record.description))
    for id, seq in sequences_dict.items():
        if seq == query_seq:
            count += 1
            output_file.write("{}\t".format(id))
    processed_counter += 1
    output_file.write("\n")
    print("processed protein "+str(processed_counter))
    output_file_2.write(record.description+'\t'+str(count)+'\t'+str(len(record.seq))+'\t'+str(record.seq)+'\n')
output_file.close()
output_file_2.close()
print("Done in --- {:.3f} seconds ---".format(time.time() - start_time))

和减速器:

export function createNew(personId) {
 const personEntry = fromJS({
  [personId] : {
  id: personId, 
  somestring: "foo",
   }
 });
 return {
  type: NEW_THING,
  personEntry,
 };
}

以及通过peopleList呈现的组件

const initialState = fromJS({
 peopleList: {},
});

 ...
case NEW_THING:   
        return state
            .update('peopleList', map => map.merge(action.personEntry));

,然后在function PeopleThumbnails(props) { const list = props.list; const listItems = list.map(item => <li>{item.get('somestring')}</li> ); return ( <ul> {listItems} </ul> ) }; export default PeopleThumbnails; 中使用它:

index.js

现在,用户执行了<PeopleThumbnails list={collection}> ... ... const mapStateToProps = createStructuredSelector({ collection: myReselectSelector() }) createNew('one')这些操作,除了索引/ personId的流氓渲染之外,其他所有操作都正常进行。

createNew('two')

0 个答案:

没有答案