Skip to content

Commit

Permalink
Add the unsetOutputChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
SejoongDeJang committed Oct 27, 2020
1 parent f8eb42c commit 0891250
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 34 deletions.
43 changes: 19 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,33 +88,46 @@ We will not describe how to do these installations as there are many ways to do

.witsconfig.json, .witsignore files are only added at the your tizen web application.

### WITs command options
### WITs CLI

#### 1. `wits`
#### `wits`

For showing which options you can use

#### 2. `wits -i` / `wits --init`
#### `wits -i` / `wits --init`

For configuring WITs
Please note that, It should be run when you use first time on your tizen application project.
.witsconfig.json and .witsignore files are generated on your tizen app project.
After then, you can modify your information to them.
![witsi](https://user-images.githubusercontent.com/1733182/77503919-3ddef280-6ea2-11ea-9bb4-06f3cb9ebbc6.gif)

#### 3. `wits -c` / `wits --certificate`
#### `wits -c` / `wits --certificate`

For creating a certification(Supported Tizen certification only).
As following steps, you can create a certification on `~/{path-to}/wits/resource/profiles.xml`.
![witsc](https://user-images.githubusercontent.com/1733182/92706471-7fe7ec00-f38f-11ea-8d47-47b13f956906.gif)

#### 4. `wits -s` / `wits --start`
#### `wits -s` / `wits --start`

All in one. For connecting to TV, installing and launching your app and using Live Reload
If `wits -i` hasn't run before, It is not allowed to run.
![witss](https://user-images.githubusercontent.com/1733182/77503927-420b1000-6ea2-11ea-88f5-49ab0c5fc227.gif)

#### 5. `wits -w` / `wits --watch`
#### `wits -w` / `wits --watch`

For conneting to TV, using Live Reload
After connecting, every time you make changes on `your tizen app project`, It is reflected to TV device instantly.
![witsw](https://user-images.githubusercontent.com/1733182/77503928-43d4d380-6ea2-11ea-8ece-4f5182cb7d6d.gif)

### WITs API

WITs support followed APIs

- `setWitsconfigInfo(WitsInfoData data)` : This API is for setting WITs environment, It should be called before start function or watch function.
-
-
- For detail, check the [How to use WITs as APIs](https://github.com/Samsung/Wits/wiki/How-to-use-WITs-as-APIs).

### .witsconfig.json of WITs

Expand Down Expand Up @@ -145,24 +158,6 @@ deprecated
stglib
```

## Running Your App

### wits -i

![witsi](https://user-images.githubusercontent.com/1733182/77503919-3ddef280-6ea2-11ea-9bb4-06f3cb9ebbc6.gif)

### wits -c

![witsc](https://user-images.githubusercontent.com/1733182/92706471-7fe7ec00-f38f-11ea-8d47-47b13f956906.gif)

### wits -s

![witss](https://user-images.githubusercontent.com/1733182/77503927-420b1000-6ea2-11ea-88f5-49ab0c5fc227.gif)

### wits -w

![witsw](https://user-images.githubusercontent.com/1733182/77503928-43d4d380-6ea2-11ea-8ece-4f5182cb7d6d.gif)

## FAQ

- [WITs FAQ](https://github.com/Samsung/Wits/wiki/Frequently-Asked-Questions)
Expand Down
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const util = require('./lib/util.js');
const userInfoHelper = require('./lib/userInfoHelper.js');
const { setOutputChannel, logger } = require('./lib/logger');
const {
setOutputChannel,
unsetOutputChannel,
logger
} = require('./lib/logger');

const setWitsconfigInfo = async data => {
try {
Expand Down Expand Up @@ -84,5 +88,6 @@ module.exports = {
start,
watch,
disconnect,
setOutputChannel
setOutputChannel,
unsetOutputChannel
};
37 changes: 29 additions & 8 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,52 @@ const setOutputChannel = output => {
if (typeof output !== 'function') {
throw new Error(`output should be function`);
}
outputChannel.push(output);
const id = generateId();
outputChannel.push({ id, output });
return id;
};

function generateId() {
const min = Math.ceil(1000);
const max = Math.floor(9999);
return Math.floor(Math.random() * (max - min)) + min;
}

const unsetOutputChannel = requestId => {
const removedId = outputChannel.findIndex(({ id }) => requestId === id);
if (removedId < 0) {
console.error(`The request id(${requestId}) is not exist`);
return;
}
outputChannel.splice(removedId, 1);
};

function error() {
var args = [].slice.call(arguments);
[console.error, ...outputChannel].forEach(print => {
const args = [].slice.call(arguments);
const outputCallback = outputChannel.map(({ output }) => output);
[console.error, ...outputCallback].forEach(print => {
print(...args);
});
}

function warn() {
var args = [].slice.call(arguments);
[console.warn, ...outputChannel].forEach(print => {
const args = [].slice.call(arguments);
const outputCallback = outputChannel.map(({ output }) => output);
[console.warn, ...outputCallback].forEach(print => {
print(...args);
});
}

function log() {
var args = [].slice.call(arguments);
[console.log, ...outputChannel].forEach(print => {
const args = [].slice.call(arguments);
const outputCallback = outputChannel.map(({ output }) => output);
[console.log, ...outputCallback].forEach(print => {
print(...args);
});
}

function debug() {
var args = [].slice.call(arguments);
const args = [].slice.call(arguments);
console.debug(...args);
}

Expand All @@ -42,5 +62,6 @@ const logger = {

module.exports = {
setOutputChannel,
unsetOutputChannel,
logger
};

0 comments on commit 0891250

Please sign in to comment.