|
| 1 | +/* |
| 2 | + * ArticleViwerStore store |
| 3 | + * |
| 4 | + */ |
| 5 | + |
| 6 | +import{typesast,getParent}from'mobx-state-tree' |
| 7 | +importRfrom'ramda' |
| 8 | + |
| 9 | +import{markStates,makeDebugger,TYPE}from'../../utils' |
| 10 | +/* eslint-disable no-unused-vars */ |
| 11 | +constdebug=makeDebugger('S:ArticleViwerStore') |
| 12 | +/* eslint-enable no-unused-vars */ |
| 13 | + |
| 14 | +constPost=t.model('Post',{ |
| 15 | +id:t.optional(t.string,''), |
| 16 | +title:t.optional(t.string,''), |
| 17 | +body:t.optional(t.string,''), |
| 18 | +digest:t.optional(t.string,''), |
| 19 | +views:t.optional(t.number,0), |
| 20 | +// author: Author, |
| 21 | +tags:t.optional(t.string,''),// TODO: ArrayOf Tag |
| 22 | +comments:t.optional(t.string,''),// TODO: ArrayOf comments |
| 23 | +favoritedCount:t.optional(t.number,0), |
| 24 | +starredCount:t.optional(t.number,0), |
| 25 | +viewerHasFavorited:t.optional(t.boolean,false), |
| 26 | +viewerHasStarred:t.optional(t.boolean,false), |
| 27 | +insertedAt:t.optional(t.string,''), |
| 28 | +updatedAt:t.optional(t.string,''), |
| 29 | +}) |
| 30 | + |
| 31 | +constArticleViwerStore=t |
| 32 | +.model('ArticleViwerStore',{ |
| 33 | +type:t.optional( |
| 34 | +t.enumeration('type',[ |
| 35 | +TYPE.POST, |
| 36 | +TYPE.JOB, |
| 37 | +// ... |
| 38 | +]), |
| 39 | +TYPE.POST |
| 40 | +), |
| 41 | +post:t.optional(Post,{}), |
| 42 | +postLoading:t.optional(t.boolean,false), |
| 43 | +}) |
| 44 | +.views(self=>({ |
| 45 | +getroot(){ |
| 46 | +returngetParent(self) |
| 47 | +}, |
| 48 | +getcurPost(){ |
| 49 | +returnself.post.toJSON() |
| 50 | +}, |
| 51 | +})) |
| 52 | +.actions(self=>({ |
| 53 | +load(upperType,data){ |
| 54 | +consttype=R.toLower(upperType) |
| 55 | +self.markState({ |
| 56 | +type:upperType, |
| 57 | +[type]:R.merge(self[type],data), |
| 58 | +}) |
| 59 | +}, |
| 60 | +markState(sobj){ |
| 61 | +markStates(sobj,self) |
| 62 | +}, |
| 63 | +})) |
| 64 | + |
| 65 | +exportdefaultArticleViwerStore |