From 8474f3cf7f23e3c974e0bbaa8e3fa74381e469e8 Mon Sep 17 00:00:00 2001
From: Daniel Gasienica <daniel@signal.org>
Date: Tue, 3 Apr 2018 15:25:24 -0400
Subject: [PATCH] Use `create*` prefix to clarify curried functions

---
 app/attachments.js           | 22 ++++++++++++----------
 js/modules/debug.js          |  2 +-
 preload.js                   |  6 +++---
 test/app/attachments_test.js | 18 +++++++++---------
 4 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/app/attachments.js b/app/attachments.js
index 46dca8589..7177118f5 100644
--- a/app/attachments.js
+++ b/app/attachments.js
@@ -24,10 +24,10 @@ exports.ensureDirectory = async (userDataPath) => {
   await fse.ensureDir(exports.getPath(userDataPath));
 };
 
-//      readData :: AttachmentsPath ->
-//                  RelativePath ->
-//                  IO (Promise ArrayBuffer)
-exports.readData = (root) => {
+//      createReader :: AttachmentsPath ->
+//                      RelativePath ->
+//                      IO (Promise ArrayBuffer)
+exports.createReader = (root) => {
   if (!isString(root)) {
     throw new TypeError('`root` must be a path');
   }
@@ -43,10 +43,10 @@ exports.readData = (root) => {
   };
 };
 
-//      writeData :: AttachmentsPath ->
-//                   ArrayBuffer ->
-//                   IO (Promise RelativePath)
-exports.writeData = (root) => {
+//      createWriter :: AttachmentsPath ->
+//                      ArrayBuffer ->
+//                      IO (Promise RelativePath)
+exports.createWriter = (root) => {
   if (!isString(root)) {
     throw new TypeError('`root` must be a path');
   }
@@ -66,8 +66,10 @@ exports.writeData = (root) => {
   };
 };
 
-//      deleteData :: AttachmentsPath -> IO Unit
-exports.deleteData = (root) => {
+//      createDeleter :: AttachmentsPath ->
+//                       RelativePath ->
+//                       IO Unit
+exports.createDeleter = (root) => {
   if (!isString(root)) {
     throw new TypeError('`root` must be a path');
   }
diff --git a/js/modules/debug.js b/js/modules/debug.js
index 1c504e4a9..b89ee17fa 100644
--- a/js/modules/debug.js
+++ b/js/modules/debug.js
@@ -127,7 +127,7 @@ const _createMessage = ({ commonProperties, conversationId, type } = {}) => {
 };
 
 const FIXTURES_PATH = path.join(__dirname, '..', '..', 'fixtures');
-const readData = Attachments.readData(FIXTURES_PATH);
+const readData = Attachments.createReader(FIXTURES_PATH);
 const createRandomInMemoryAttachment = async () => {
   const files = (await fs.readdir(FIXTURES_PATH)).map(createFileEntry);
   const { contentType, fileName } = sample(files);
diff --git a/preload.js b/preload.js
index ba39278e6..4c998af96 100644
--- a/preload.js
+++ b/preload.js
@@ -111,9 +111,9 @@ window.ProxyAgent = require('proxy-agent');
 
 // ES2015+ modules
 const attachmentsPath = Attachments.getPath(app.getPath('userData'));
-const deleteAttachmentData = Attachments.deleteData(attachmentsPath);
-const readAttachmentData = Attachments.readData(attachmentsPath);
-const writeAttachmentData = Attachments.writeData(attachmentsPath);
+const deleteAttachmentData = Attachments.createDeleter(attachmentsPath);
+const readAttachmentData = Attachments.createReader(attachmentsPath);
+const writeAttachmentData = Attachments.createWriter(attachmentsPath);
 
 // Injected context functions to keep `Message` agnostic from Electron:
 const upgradeSchemaContext = {
diff --git a/test/app/attachments_test.js b/test/app/attachments_test.js
index a186fa62b..0fff99ac4 100644
--- a/test/app/attachments_test.js
+++ b/test/app/attachments_test.js
@@ -13,7 +13,7 @@ const NAME_LENGTH = 64;
 const PATH_LENGTH = PREFIX_LENGTH + NUM_SEPARATORS + NAME_LENGTH;
 
 describe('Attachments', () => {
-  describe('writeData', () => {
+  describe('createWriter', () => {
     let tempRootDirectory = null;
     before(() => {
       tempRootDirectory = tmp.dirSync().name;
@@ -25,9 +25,9 @@ describe('Attachments', () => {
 
     it('should write file to disk and return path', async () => {
       const input = stringToArrayBuffer('test string');
-      const tempDirectory = path.join(tempRootDirectory, 'Attachments_writeData');
+      const tempDirectory = path.join(tempRootDirectory, 'Attachments_createWriter');
 
-      const outputPath = await Attachments.writeData(tempDirectory)(input);
+      const outputPath = await Attachments.createWriter(tempDirectory)(input);
       const output = await fse.readFile(path.join(tempDirectory, outputPath));
 
       assert.lengthOf(outputPath, PATH_LENGTH);
@@ -37,7 +37,7 @@ describe('Attachments', () => {
     });
   });
 
-  describe('readData', () => {
+  describe('createReader', () => {
     let tempRootDirectory = null;
     before(() => {
       tempRootDirectory = tmp.dirSync().name;
@@ -48,7 +48,7 @@ describe('Attachments', () => {
     });
 
     it('should read file from disk', async () => {
-      const tempDirectory = path.join(tempRootDirectory, 'Attachments_readData');
+      const tempDirectory = path.join(tempRootDirectory, 'Attachments_createReader');
 
       const relativePath = Attachments.getRelativePath(Attachments.createName());
       const fullPath = path.join(tempDirectory, relativePath);
@@ -57,13 +57,13 @@ describe('Attachments', () => {
       const inputBuffer = Buffer.from(input);
       await fse.ensureFile(fullPath);
       await fse.writeFile(fullPath, inputBuffer);
-      const output = await Attachments.readData(tempDirectory)(relativePath);
+      const output = await Attachments.createReader(tempDirectory)(relativePath);
 
       assert.deepEqual(input, output);
     });
   });
 
-  describe('deleteData', () => {
+  describe('createDeleter', () => {
     let tempRootDirectory = null;
     before(() => {
       tempRootDirectory = tmp.dirSync().name;
@@ -74,7 +74,7 @@ describe('Attachments', () => {
     });
 
     it('should delete file from disk', async () => {
-      const tempDirectory = path.join(tempRootDirectory, 'Attachments_deleteData');
+      const tempDirectory = path.join(tempRootDirectory, 'Attachments_createDeleter');
 
       const relativePath = Attachments.getRelativePath(Attachments.createName());
       const fullPath = path.join(tempDirectory, relativePath);
@@ -83,7 +83,7 @@ describe('Attachments', () => {
       const inputBuffer = Buffer.from(input);
       await fse.ensureFile(fullPath);
       await fse.writeFile(fullPath, inputBuffer);
-      await Attachments.deleteData(tempDirectory)(relativePath);
+      await Attachments.createDeleter(tempDirectory)(relativePath);
 
       const existsFile = await fse.exists(fullPath);
       assert.isFalse(existsFile);