{"action":"created","comment":{"url":"https://api.github.com/repos/Paulonov/coding-challenge-js/pulls/comments/30495885","id":30495885,"diff_hunk":"@@ -0,0 +1,392 @@\n+/**\n+ * ui.jsx\n+ *\n+ * A file describing the UI of the application using React. A lot of the state accesses occur on the state property\n+ * which apparently isn't the best practice but it gets rid of lots of unnecessary re-renders.\n+ *\n+ */\n+\"use strict\";\n+/*eslint-disable no-console, no-underscore-dangle*/\n+\n+import React from \"react\";\n+\n+import { executeInstruction, getFancyPositionInformation } from \"./robot.js\";\n+import { parseInstructions, prepareRobots } from \"./instructionreader.js\";\n+\n+export default class MartianRobots extends React.Component {\n+\n+    render() {\n+\n+        return (\n+            <div id=\"appContainer\">\n+                <Header />\n+                <World />\n+            </div>\n+        );\n+\n+    }\n+\n+}\n+\n+/**\n+ * The header bar at the top of the page.\n+ */\n+class Header extends React.Component {\n+\n+    render() {\n+        return (\n+            <div id=\"header\">\n+                <p>Martian Robots</p>\n+            </div>\n+        );\n+    }\n+\n+}\n+\n+/**\n+ * State entirely resides here; if it's need elsewhere, it can be passed down to child components as props.\n+ */\n+class World extends React.Component {\n+\n+    constructor() {\n+\n+        super();\n+\n+        /**\n+         * State becomes immutable with some easily updatable properties. Every tick of the world updates the entire\n+         * world state so that React can re-render it.\n+         * @type {Object}\n+         */\n+        this.state = {\n+\n+            // Every robot that exists in the world and its state\n+            robots: [],\n+\n+            // The state of the planet\n+            planet: {\n+                scents: {\n+                    // E.g. \"5,2\": true\n+                },\n+                rows: 0,\n+                cols: 0\n+            },\n+\n+            outputMessages: []\n+\n+        };\n+\n+        this.setIntervalId = -1;\n+\n+        // TODO: Used for debugging, push state to this array after every tick so we can examine it later\n+        this.savedStates = [];\n+\n+    }\n+\n+    /**\n+     * Set the initial state of the world.\n+     * @param  {String} instructionsString The user's input taken straight from the editor.\n+     */\n+    _setup(instructionsString) {\n+\n+        var instructionStack;\n+\n+        // Convert the instructions passed in by the user into a stack\n+        try {\n+            instructionStack = parseInstructions(instructionsString);\n+        } catch (error) {\n+            console.log(error);\n+            return;\n+        }\n+\n+        // The first item on the stack is the planet's boundaries\n+        var planetBoundaries = instructionStack.pop().trim().split(\" \");\n+\n+        // Use the instruction stack to set the initial state of the world\n+        var initialRobots = prepareRobots(instructionStack, planetBoundaries);\n+        var initialPlanet = { scents: {}, rows: parseInt(planetBoundaries[0], 10), cols: parseInt(planetBoundaries[1], 10) };\n+\n+        // Update the state of the world accordingly: The callback starts the simulation\n+        this.setState({ robots: initialRobots, planet: initialPlanet },\n+\n+            () => {\n+                this.setIntervalId = setInterval(this._tick.bind(this), 100);\n+            }\n+\n+        );\n+\n+    }\n+\n+    // Update everything in the world by one instruction\n+    // TODO: Make all of the data accesses immutable\n+    _tick() {\n+\n+        // Use executeInstruction once on each robot to get the next state of the world\n+        var planet = this.state.planet;\n+        var robots = this.state.robots;\n+        var outputMessages = this.state.outputMessages.slice(0);\n+        var doneCount = 0;\n+\n+        // Map is immutable, return result to new array\n+        var newRobots = robots.map( robot => {\n+\n+                // If the robot does not have any instructions to execute or is lost, bail\n+                if (robot.lost || robot.instructions.length === 0) {\n+                    doneCount++;\n+                    return robot;\n+                }\n+\n+                // Get a new robot by updating the state of the current one being processed\n+                var newRobot = executeInstruction(robot, planet, robot.instructions[robot.instructions.length - 1]);\n+                newRobot.instructions.pop();\n+\n+                if (newRobot.lost) {\n+                    // Leave a scent\n+                    this.setState({ planet: { scents: { [`${newRobot.x},${newRobot.y}`]: true } } } );\n+                }\n+\n+                return newRobot;\n+\n+            }\n+\n+        );\n+\n+        // TODO: Debugging, push the current state so we can examine it later\n+        this.savedStates.push(this.state);\n+\n+        // If every robot is done, we're finished\n+        if (doneCount === robots.length) {\n+\n+            robots.map( robot => {\n+                outputMessages.push(getFancyPositionInformation(robot));\n+            });\n+\n+            console.log(this.savedStates);\n+\n+            // Stop our update ticks and do a final state update\n+            clearInterval(this.setIntervalId);\n+            this.setState({robots: newRobots, outputMessages: outputMessages});\n+\n+            return;\n+\n+        }\n+\n+        this.setState({\n+            robots: newRobots\n+        });\n+\n+        return;\n+\n+    }\n+\n+    render() {\n+\n+        // 0 is falsey so if the planet is 0, 0 it is undefined and we need to set everything up\n+        if (!(this.state.planet.rows && this.state.planet.cols)) {\n+            return (\n+                <div id=\"mainArea\">\n+                    <div id=\"graphicsContainer\"></div>\n+                    <SideBar _setup={this._setup.bind(this)} />\n+                    <OutputBox outputData={this.state.outputMessages} />\n+                </div>\n+            );\n+        }\n+\n+        return (","path":"src/ui.jsx","position":194,"original_position":194,"commit_id":"dcccd48be70e16a5ccd41e2f26c56bda009df7b2","original_commit_id":"dcccd48be70e16a5ccd41e2f26c56bda009df7b2","user":{"login":"JoeStanton","id":1161508,"avatar_url":"https://avatars.githubusercontent.com/u/1161508?v=3","gravatar_id":"","url":"https://api.github.com/users/JoeStanton","html_url":"https://github.com/JoeStanton","followers_url":"https://api.github.com/users/JoeStanton/followers","following_url":"https://api.github.com/users/JoeStanton/following{/other_user}","gists_url":"https://api.github.com/users/JoeStanton/gists{/gist_id}","starred_url":"https://api.github.com/users/JoeStanton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoeStanton/subscriptions","organizations_url":"https://api.github.com/users/JoeStanton/orgs","repos_url":"https://api.github.com/users/JoeStanton/repos","events_url":"https://api.github.com/users/JoeStanton/events{/privacy}","received_events_url":"https://api.github.com/users/JoeStanton/received_events","type":"User","site_admin":false},"body":"In relation to the above ^","created_at":"2015-05-18T10:18:45Z","updated_at":"2015-05-18T10:18:45Z","html_url":"https://github.com/Paulonov/coding-challenge-js/pull/2#discussion_r30495885","pull_request_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/Paulonov/coding-challenge-js/pulls/comments/30495885"},"html":{"href":"https://github.com/Paulonov/coding-challenge-js/pull/2#discussion_r30495885"},"pull_request":{"href":"https://api.github.com/repos/Paulonov/coding-challenge-js/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/Paulonov/coding-challenge-js/pulls/2","id":35618987,"html_url":"https://github.com/Paulonov/coding-challenge-js/pull/2","diff_url":"https://github.com/Paulonov/coding-challenge-js/pull/2.diff","patch_url":"https://github.com/Paulonov/coding-challenge-js/pull/2.patch","issue_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/issues/2","number":2,"state":"open","locked":false,"title":"React Rewrite - Feedback","user":{"login":"JoeStanton","id":1161508,"avatar_url":"https://avatars.githubusercontent.com/u/1161508?v=3","gravatar_id":"","url":"https://api.github.com/users/JoeStanton","html_url":"https://github.com/JoeStanton","followers_url":"https://api.github.com/users/JoeStanton/followers","following_url":"https://api.github.com/users/JoeStanton/following{/other_user}","gists_url":"https://api.github.com/users/JoeStanton/gists{/gist_id}","starred_url":"https://api.github.com/users/JoeStanton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoeStanton/subscriptions","organizations_url":"https://api.github.com/users/JoeStanton/orgs","repos_url":"https://api.github.com/users/JoeStanton/repos","events_url":"https://api.github.com/users/JoeStanton/events{/privacy}","received_events_url":"https://api.github.com/users/JoeStanton/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-05-18T10:09:47Z","updated_at":"2015-05-18T10:18:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"221e0077951206d3142c011eb9a929593c644ab5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/pulls/2/commits","review_comments_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/pulls/2/comments","review_comment_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/issues/2/comments","statuses_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/statuses/dcccd48be70e16a5ccd41e2f26c56bda009df7b2","head":{"label":"Paulonov:react-rewrite","ref":"react-rewrite","sha":"dcccd48be70e16a5ccd41e2f26c56bda009df7b2","user":{"login":"Paulonov","id":1245666,"avatar_url":"https://avatars.githubusercontent.com/u/1245666?v=3","gravatar_id":"","url":"https://api.github.com/users/Paulonov","html_url":"https://github.com/Paulonov","followers_url":"https://api.github.com/users/Paulonov/followers","following_url":"https://api.github.com/users/Paulonov/following{/other_user}","gists_url":"https://api.github.com/users/Paulonov/gists{/gist_id}","starred_url":"https://api.github.com/users/Paulonov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Paulonov/subscriptions","organizations_url":"https://api.github.com/users/Paulonov/orgs","repos_url":"https://api.github.com/users/Paulonov/repos","events_url":"https://api.github.com/users/Paulonov/events{/privacy}","received_events_url":"https://api.github.com/users/Paulonov/received_events","type":"User","site_admin":false},"repo":{"id":30714131,"name":"coding-challenge-js","full_name":"Paulonov/coding-challenge-js","owner":{"login":"Paulonov","id":1245666,"avatar_url":"https://avatars.githubusercontent.com/u/1245666?v=3","gravatar_id":"","url":"https://api.github.com/users/Paulonov","html_url":"https://github.com/Paulonov","followers_url":"https://api.github.com/users/Paulonov/followers","following_url":"https://api.github.com/users/Paulonov/following{/other_user}","gists_url":"https://api.github.com/users/Paulonov/gists{/gist_id}","starred_url":"https://api.github.com/users/Paulonov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Paulonov/subscriptions","organizations_url":"https://api.github.com/users/Paulonov/orgs","repos_url":"https://api.github.com/users/Paulonov/repos","events_url":"https://api.github.com/users/Paulonov/events{/privacy}","received_events_url":"https://api.github.com/users/Paulonov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Paulonov/coding-challenge-js","description":"An HTML5/JavaScript implementation of the Red Badger coding challenge.","fork":false,"url":"https://api.github.com/repos/Paulonov/coding-challenge-js","forks_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/forks","keys_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/teams","hooks_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/hooks","issue_events_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/issues/events{/number}","events_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/events","assignees_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/assignees{/user}","branches_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/branches{/branch}","tags_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/tags","blobs_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/statuses/{sha}","languages_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/languages","stargazers_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/stargazers","contributors_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/contributors","subscribers_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/subscribers","subscription_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/subscription","commits_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/contents/{+path}","compare_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/merges","archive_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/downloads","issues_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/issues{/number}","pulls_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/pulls{/number}","milestones_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/milestones{/number}","notifications_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/labels{/name}","releases_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/releases{/id}","created_at":"2015-02-12T17:25:11Z","updated_at":"2015-03-09T18:03:34Z","pushed_at":"2015-05-18T10:09:48Z","git_url":"git://github.com/Paulonov/coding-challenge-js.git","ssh_url":"git@github.com:Paulonov/coding-challenge-js.git","clone_url":"https://github.com/Paulonov/coding-challenge-js.git","svn_url":"https://github.com/Paulonov/coding-challenge-js","homepage":null,"size":651,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"Paulonov:master","ref":"master","sha":"e9df69b14fb946c2278c2cd166009449a24b7daf","user":{"login":"Paulonov","id":1245666,"avatar_url":"https://avatars.githubusercontent.com/u/1245666?v=3","gravatar_id":"","url":"https://api.github.com/users/Paulonov","html_url":"https://github.com/Paulonov","followers_url":"https://api.github.com/users/Paulonov/followers","following_url":"https://api.github.com/users/Paulonov/following{/other_user}","gists_url":"https://api.github.com/users/Paulonov/gists{/gist_id}","starred_url":"https://api.github.com/users/Paulonov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Paulonov/subscriptions","organizations_url":"https://api.github.com/users/Paulonov/orgs","repos_url":"https://api.github.com/users/Paulonov/repos","events_url":"https://api.github.com/users/Paulonov/events{/privacy}","received_events_url":"https://api.github.com/users/Paulonov/received_events","type":"User","site_admin":false},"repo":{"id":30714131,"name":"coding-challenge-js","full_name":"Paulonov/coding-challenge-js","owner":{"login":"Paulonov","id":1245666,"avatar_url":"https://avatars.githubusercontent.com/u/1245666?v=3","gravatar_id":"","url":"https://api.github.com/users/Paulonov","html_url":"https://github.com/Paulonov","followers_url":"https://api.github.com/users/Paulonov/followers","following_url":"https://api.github.com/users/Paulonov/following{/other_user}","gists_url":"https://api.github.com/users/Paulonov/gists{/gist_id}","starred_url":"https://api.github.com/users/Paulonov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Paulonov/subscriptions","organizations_url":"https://api.github.com/users/Paulonov/orgs","repos_url":"https://api.github.com/users/Paulonov/repos","events_url":"https://api.github.com/users/Paulonov/events{/privacy}","received_events_url":"https://api.github.com/users/Paulonov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Paulonov/coding-challenge-js","description":"An HTML5/JavaScript implementation of the Red Badger coding challenge.","fork":false,"url":"https://api.github.com/repos/Paulonov/coding-challenge-js","forks_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/forks","keys_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/teams","hooks_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/hooks","issue_events_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/issues/events{/number}","events_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/events","assignees_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/assignees{/user}","branches_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/branches{/branch}","tags_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/tags","blobs_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/statuses/{sha}","languages_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/languages","stargazers_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/stargazers","contributors_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/contributors","subscribers_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/subscribers","subscription_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/subscription","commits_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/contents/{+path}","compare_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/merges","archive_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/downloads","issues_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/issues{/number}","pulls_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/pulls{/number}","milestones_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/milestones{/number}","notifications_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/labels{/name}","releases_url":"https://api.github.com/repos/Paulonov/coding-challenge-js/releases{/id}","created_at":"2015-02-12T17:25:11Z","updated_at":"2015-03-09T18:03:34Z","pushed_at":"2015-05-18T10:09:48Z","git_url":"git://github.com/Paulonov/coding-challenge-js.git","ssh_url":"git@github.com:Paulonov/coding-challenge-js.git","clone_url":"https://github.com/Paulonov/coding-challenge-js.git","svn_url":"https://github.com/Paulonov/coding-challenge-js","homepage":null,"size":651,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Paulonov/coding-challenge-js/pulls/2"},"html":{"href":"https://github.com/Paulonov/coding-challenge-js/pull/2"},"issue":{"href":"https://api.github.com/repos/Paulonov/coding-challenge-js/issues/2"},"comments":{"href":"https://api.github.com/repos/Paulonov/coding-challenge-js/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/Paulonov/coding-challenge-js/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/Paulonov/coding-challenge-js/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Paulonov/coding-challenge-js/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/Paulonov/coding-challenge-js/statuses/dcccd48be70e16a5ccd41e2f26c56bda009df7b2"}}}}