Skip to content

Commit

Permalink
Format all javascript files
Browse files Browse the repository at this point in the history
  • Loading branch information
trampboy committed May 16, 2020
1 parent af4a415 commit 13a8c6a
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 154 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly",
"module": true,
"require": true
"require": true,
"wx": true,
},
"parser": "babel-eslint",
"parserOptions": {
Expand Down
4 changes: 2 additions & 2 deletions example/mini-program/pages/notepad/notepad.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ Page({
data: {
scanResult: null
},
onLoad: function (options) {
onLoad: function () {
const eventChannel = this.getOpenerEventChannel();
eventChannel.on("scanResult", function(data) {
eventChannel.on('scanResult', function (data) {
this.data.scanResult = data.scanResult;
});
},
Expand Down
2 changes: 1 addition & 1 deletion src/Notepad.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { optionalServices as WoodemiOptionalServices } from "./woodemi/WoodemiClient.js";

export const optionalServiceCollection = [
...WoodemiOptionalServices
...WoodemiOptionalServices
];
22 changes: 11 additions & 11 deletions src/NotepadClient.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { WOODEMI_PREFIX } from "./woodemi/Woodemi.js";

Uint8Array.prototype.startWith = function (prefix) {
if (this.length < prefix.length) return false
if (this.length < prefix.length) return false;

for (let i in prefix) {
if (this[i] != prefix[i]) return false
}
return true
}
for (let i in prefix) {
if (this[i] != prefix[i]) return false;
}
return true;
};

export default class NotepadClient {
static support(scanResult) {
if (scanResult.manufacturerData.startWith(WOODEMI_PREFIX)) {
return true;
}
return false;
static support(scanResult) {
if (scanResult.manufacturerData.startWith(WOODEMI_PREFIX)) {
return true;
}
return false;
}
}
6 changes: 3 additions & 3 deletions src/NotepadCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export default class NotepadCommand {
handle;

constructor(request, intercept, handle) {
this.request = request;
this.intercept = intercept;
this.handle = handle;
this.request = request;
this.intercept = intercept;
this.handle = handle;
}
}
86 changes: 43 additions & 43 deletions src/NotepadConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,74 @@ import { optionalServiceCollection } from "./Notepad.js";
import NotepadClient from "./NotepadClient.js";

class NotepadConnector {
constructor() {
notepadCore.messageHandler = this._handleMessage.bind(this);
}
constructor() {
notepadCore.messageHandler = this._handleMessage.bind(this);
}

requestDevice() {
console.info("NotepadConnector requestDevice");
return notepadCore.requestDevice({
optionalServices: optionalServiceCollection
});
}
requestDevice() {
console.info("NotepadConnector requestDevice");
return notepadCore.requestDevice({
optionalServices: optionalServiceCollection
});
}

startScan() {
console.info("NotepadConnector startScan");
notepadCore.startScan();
}
startScan() {
console.info("NotepadConnector startScan");
notepadCore.startScan();
}

stopScan() {
console.info("NotepadConnector stopScan");
notepadCore.stopScan();
}
stopScan() {
console.info("NotepadConnector stopScan");
notepadCore.stopScan();
}

onScanResult() {}
onScanResult() {}

connect(notepadScanResult, authToken) {}
connect(notepadScanResult, authToken) {}

disconnect() {}
disconnect() {}

claimAuth() {}
claimAuth() {}

disclaimAuth() {}
disclaimAuth() {}

setMode(mode) {}
setMode(mode) {}

onReceiveNotePenPointers() {}
onReceiveNotePenPointers() {}

getMemoSummary() {}
getMemoSummary() {}

importMemo() {}
importMemo() {}

onImportMemoProgress() {}
onImportMemoProgress() {}

deleteMemo() {}
deleteMemo() {}

getDeviceName() {}
getDeviceName() {}

setDeviceName(name) {}
setDeviceName(name) {}

getBatteryInfo() {}
getBatteryInfo() {}

getDeviceDate() {}
getDeviceDate() {}

setDeviceDate(timestamp) {}
setDeviceDate(timestamp) {}

getAutoLockTime() {}
getAutoLockTime() {}

setAutoLockTime(duration) {}
setAutoLockTime(duration) {}

upgrade(path, version) {}
upgrade(path, version) {}

onUpgradeProgress() {}
onUpgradeProgress() {}

_handleMessage(message) {
console.debug("NotepadConnector _handleMessage", message);
if (message.name === "scanResult") {
if (NotepadClient.support(message.scanResult) && this.scanResultHandler)
this.scanResultHandler(message.scanResult);
}
_handleMessage(message) {
console.debug("NotepadConnector _handleMessage", message);
if (message.name === "scanResult") {
if (NotepadClient.support(message.scanResult) && this.scanResultHandler)
this.scanResultHandler(message.scanResult);
}
}
}

export default NotepadConnector;
52 changes: 26 additions & 26 deletions src/NotepadType.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,47 @@ class NotepadType {
#notepadClient;

constructor(notepadClient) {
this.#notepadClient = notepadClient;
this.#notepadClient.notepadType = this;
this.#notepadClient = notepadClient;
this.#notepadClient.notepadType = this;
}

async configCharacteristics() {
for (let serviceCharacteristic of this.#notepadClient.inputIndicationCharacteristics) {
await notepadCore.setNotifiable(serviceCharacteristic);
}
for (let serviceCharacteristic of this.#notepadClient.inputNotificationCharacteristics) {
await notepadCore.setNotifiable(serviceCharacteristic);
}
for (let serviceCharacteristic of this.#notepadClient.inputIndicationCharacteristics) {
await notepadCore.setNotifiable(serviceCharacteristic);
}
for (let serviceCharacteristic of this.#notepadClient.inputNotificationCharacteristics) {
await notepadCore.setNotifiable(serviceCharacteristic);
}
}

async sendRequestAsync(messageHead, serviceCharacteristic, request) {
await notepadCore.writeValue(serviceCharacteristic, request);
console.log(`on${messageHead}Send: ${request}`);
await notepadCore.writeValue(serviceCharacteristic, request);
console.log(`on${messageHead}Send: ${request}`);
}

receiveResponseAsync(messageHead, serviceCharacteristic, predicate) {
const [service, characteristic] = serviceCharacteristic;
return new Promise(function (resolve, reject) {
let filter = function (value) {
if (predicate(value)) {
notepadCore.inputValueEmitter.removeListener(characteristic, filter);
console.log(`on${messageHead}Receive: ${characteristic} ${value}`);
resolve(value);
}
};
notepadCore.inputValueEmitter.addListener(characteristic, filter);
});
const [service, characteristic] = serviceCharacteristic;
return new Promise(function (resolve, reject) {
let filter = function (value) {
if (predicate(value)) {
notepadCore.inputValueEmitter.removeListener(characteristic, filter);
console.log(`on${messageHead}Receive: ${characteristic} ${value}`);
resolve(value);
}
};
notepadCore.inputValueEmitter.addListener(characteristic, filter);
});
}

async executeCommand(command) {
await this.sendRequestAsync("Command", this.#notepadClient.commandRequestCharacteristic, command.request);
let value = await this.receiveResponseAsync("Command", this.#notepadClient.commandResponseCharacteristic, command.intercept);
return command.handle(value);
await this.sendRequestAsync("Command", this.#notepadClient.commandRequestCharacteristic, command.request);
let value = await this.receiveResponseAsync("Command", this.#notepadClient.commandResponseCharacteristic, command.intercept);
return command.handle(value);
}

receiveSyncInput(receiver) {
const [service, characteristic] = this.#notepadClient.syncInputCharacteristic;
notepadCore.inputValueEmitter.addListener(characteristic, receiver);
const [service, characteristic] = this.#notepadClient.syncInputCharacteristic;
notepadCore.inputValueEmitter.addListener(characteristic, receiver);
}
}

Expand Down
40 changes: 20 additions & 20 deletions src/events.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
export default class EventEmitter {
constructor() {
this.events = {};
}
constructor() {
this.events = {};
}

addListener(event, listener) {
if (typeof this.events[event] !== 'object') {
this.events[event] = [];
}
this.events[event].push(listener);
return () => this.removeListener(event, listener);
addListener(event, listener) {
if (typeof this.events[event] !== 'object') {
this.events[event] = [];
}
this.events[event].push(listener);
return () => this.removeListener(event, listener);
}

removeListener(event, listener) {
if (typeof this.events[event] === 'object') {
const idx = this.events[event].indexOf(listener);
if (idx > -1) {
this.events[event].splice(idx, 1);
}
}
removeListener(event, listener) {
if (typeof this.events[event] === 'object') {
const idx = this.events[event].indexOf(listener);
if (idx > -1) {
this.events[event].splice(idx, 1);
}
}
}

emit(event, ...args) {
if (typeof this.events[event] === 'object') {
this.events[event].forEach((listener) => listener.apply(this, args));
}
emit(event, ...args) {
if (typeof this.events[event] === 'object') {
this.events[event].forEach((listener) => listener.apply(this, args));
}
}
}
10 changes: 5 additions & 5 deletions src/models.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export const NotepadConnectionState = {
disconnected: 0,
connecting: 1,
connected: 2
disconnected: 0,
connecting: 1,
connected: 2
};

export const NotepadMode = Object.freeze({
Sync: Symbol("Sync"),
Common: Symbol("Common"),
Sync: Symbol("Sync"),
Common: Symbol("Common"),
});
Loading

0 comments on commit 13a8c6a

Please sign in to comment.