@@ -57,16 +57,20 @@ class GO_PostContent {
5757 }
5858}
5959
60+ // builder interprets a json and builds a model of the post
6061class GO_PostBuilder {
62+ // accepts a json obj and parses a post (main method to override for a custom builder with custom json)
6163 fromJsonObject ( jsonObject ) {
6264 return new GO_PostContent ( jsonObject . title , jsonObject . timestamp , jsonObject . content ) ;
6365 }
6466
67+ // accepts a json string and parses a post
6568 fromJsonString ( jsonString ) {
6669 return this . fromJsonObject ( JSON . parse ( jsonString ) ) ;
6770 }
6871}
6972
73+ // a class to represent all the loaded posts and what the class should look for when parsing a json object to get the array of posts
7074class GO_PostModel {
7175 loadedPosts = [ ]
7276 jsonArrayVarName = "" ;
@@ -100,6 +104,7 @@ class GO_PostModel {
100104 }
101105}
102106
107+ // a class to control where the post is shown in the HTML
103108class GO_PostView {
104109 htmlIDToLookup = "" ;
105110
@@ -117,6 +122,7 @@ class GO_PostView {
117122 }
118123}
119124
125+ // a class to store a date interval
120126class GO_DateRange {
121127 _beginDate ;
122128 _endDate ;
@@ -162,6 +168,7 @@ class GO_DateRange {
162168 }
163169}
164170
171+ // a class to store the regex required to complete a search
165172class GO_SearchQuery {
166173 titleRegex = new RegExp ( '' , 'g' ) ;
167174 timestampFilter = new GO_DateRange ( new Date ( ) , new Date ( ) ) ;
@@ -180,6 +187,7 @@ class GO_SearchQuery {
180187 this . titleRegex = regex ;
181188 }
182189
190+ // scoring function attributes a value to each post that is based on the number of matches within the post
183191 scoringFunc ( post ) {
184192 // get title matches based on regex
185193 let titleRegexResult = post . title . matchAll ( this . titleRegex ) ;
@@ -206,6 +214,7 @@ class GO_SearchQuery {
206214 return [ titleScore , contentScore , timestampScore [ 0 ] , timestampScore [ 1 ] ] ;
207215 }
208216
217+ // filter out posts that do and don't match the criterion
209218 filterFunc ( post ) {
210219 let scores = this . scoringFunc ( post ) ;
211220 let titleResult = this . targetTitle ? scores [ 0 ] > 0 : true ;
@@ -214,6 +223,7 @@ class GO_SearchQuery {
214223 return titleResult && contentResult && timestampResult ;
215224 }
216225
226+ // sorting function to dictate order of which posts are shown in via score value
217227 compareFunc ( postA , postB ) {
218228 let scoreA = this . scoringFunc ( postA ) ;
219229 let scoreB = this . scoringFunc ( postB ) ;
@@ -226,6 +236,7 @@ class GO_SearchQuery {
226236 }
227237}
228238
239+ // a class that acts as the controller for the model and view components (resulting in the MVC pattern)
229240class GO_PostSystem {
230241 postModel = new GO_PostModel ( ) ;
231242 postBuilder = new GO_PostBuilder ( ) ;
@@ -253,23 +264,26 @@ class GO_PostSystem {
253264 this . postModel . removePoseOnIndices ( indices ) ;
254265 }
255266
267+ // filters and then sorts the intermediate posts (that should be rendered)
256268 filterPosts ( searchQuery ) {
257269 this . intermediatePosts = this . postModel . loadedPosts . filter ( post => searchQuery . filterFunc ( post ) ) ;
258270 this . intermediatePosts . sort ( ( a , b ) => this . searchQuery . compareFunc ( a , b ) ) ;
259271 }
260272
273+ // render intermediate posts unto the page dictated by the view
261274 refreshPostsOntoHTML ( ) {
262275 this . filterPosts ( this . searchQuery )
263276 this . postView . pasteOntoHTML ( this . intermediatePosts ) ;
264277 }
265278
279+ // wrapper method for loading the model from a json obj
266280 loadFromJson ( jsonObj ) {
267281 this . postModel . loadFromJson ( jsonObj ) ;
268282 }
269283}
270284
271285
272- //export {PostContent, PostBuilder, PostModel, PostView, PostSystem};
286+ // bind the classes declared here to the window so they're in global scope instead of being file-specific
273287window . GO_PostContent = GO_PostContent ;
274288window . GO_PostBuilder = GO_PostBuilder ;
275289
0 commit comments