Skip to content

Commit 58ffe4a

Browse files
committed
Minor updates
1 parent 80ee2b5 commit 58ffe4a

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

_posts/2023-02-11-dev-diaries-episode-1.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Another issue we have is despite having a lot of tests it's hard to be sure that
2828

2929
We could just risk it and fix problems as we discover them but that sounds like a lot of stress too.
3030

31-
A few years ago my friend [Tom](https://software.tomseldon.co.uk/blog/) (He's more focused on racing cars these days but I've linked to his technical writing blog which is still really good) created a section in the app for dev tooling to live which is super handy. A new tool was added which had one job…
31+
A few years ago my friend [Tom](https://www.tomseldon.co.uk) created a section in the app for dev tooling to live which is super handy. A new tool was added which had one job…
3232

3333
## The Task
3434

@@ -55,12 +55,12 @@ _isNewTransformerEnabled () {
5555
Then in each repository (the layer above the transformer) we call this method to see if we should use the old or new transformer
5656

5757
```javascript
58-
findEvidenceScores (topicId) {
58+
find (topicId) {
5959
return this._rawTopicsRepository.findRawTopic(topicId).then(raw => {
6060
return this._isNewTransformerEnabled()
6161
.then(enabled => enabled ?
62-
this._$window.newHotness.topicParser.parseEvidenceScores(raw) :
63-
TopicParser.parseEvidenceScores(raw);
62+
this._$window.newHotness.topicParser.parse(raw) :
63+
TopicParser.parse(raw);
6464
);
6565
});
6666
}
@@ -84,7 +84,6 @@ addOverride (flagName, state) {
8484

8585
Consumers of the feature flag service call `isEnabled()` which gets the status of the flag. If an override exists it ignores the original setting and instead resolves the override. We don't check for falsy because we might want to return false from the overrides.
8686

87-
8887
```javascript
8988
isEnabled (flagName) {
9089
if (this._overrides[flagName] !== undefined) {
@@ -140,8 +139,10 @@ Imagine this with promises too and its a bit of a mind ~~f*ck~~. So a ranty walk
140139
Instead we use promises as they were meant to be used and chain them. (Why didn't I do it this way to start with?!). Starting off we get the topics then with that we map over the resolved array to get more info about each topic like so:
141140

142141
```javascript
143-
this._topicRepository.findAll().then(topics => {
144-
return this._$q.all(topics.map(topic => this._topicRepository.findById(topic.id)));
142+
this._topicRepository.findAll().then((topics) => {
143+
return this._$q.all(
144+
topics.map((topic) => this._topicRepository.findById(topic.id))
145+
);
145146
});
146147
```
147148

@@ -190,10 +191,11 @@ Next up (I promise we're nearly done), we need to run the tests sequentially. No
190191
I wasn't sure how to do this but a quick stack overflow later I found my answer which was surprisingly simple!
191192

192193
```javascript
193-
jobs.reduce(
194-
(promise, job) => promise.then(() => this._test(job.repository, job.topic, job.key)),
194+
jobs.reduce(
195+
(promise, job) =>
196+
promise.then(() => this._test(job.repository, job.topic, job.key)),
195197
this._$q.resolve()
196-
)
198+
);
197199
```
198200

199201
This uses the reduce function and starts off with a resolved promise, it then chains subsequent promises for each job so we only run the next job if the previous one resolved.
@@ -218,7 +220,7 @@ _test (repository, topic, key) {
218220
}
219221
});
220222
}
221-
```
223+
```
222224

223225
This is pretty similar to the mock code earlier. We disable the flag, test, enable then test again. To compare the two results we use `JSON.stringify()` which I got from [Samantha's Blog](https://www.samanthaming.com/tidbits/33-how-to-compare-2-objects/) which advised this would do the job albeit with performance and ordering issues but both of these weren't a concern for this, we just wanted to know that they were the same output.
224226

-231 KB
Loading
-143 KB
Loading

0 commit comments

Comments
 (0)