Skip to content

Instantly share code, notes, and snippets.

View storuky's full-sized avatar

Kononenko Pavel storuky

View GitHub Profile
// Original data
{
"data": {
"level1": {
"field1": "data 1 on level 1", // changed
"level2": {
"field1": "data 1 on level 2",
"level3": {
"field1": "data 1 on level 3", //changed
"field2": "data 2 on level 3"
<template>
<div>
<form @submit.prevent="addUser">
<input type="text" v-model="form.name" />
<button type="submit">Add user</button>
</form>
<ul>
<li :key="user.id" v-for="user in users">{{user.name}}</li>
</ul>
</div>
@storuky
storuky / entities.js
Last active May 23, 2019 16:10
Entities
const store = {
namespaced: true,
state: {
users: [],
posts: []
},
mutations: {
set(state, { name, data }) {
state[name] = data;
},
const obj1 = {
field: {
key: "foo"
}
};
const obj2 = {
field: obj1.field
}
@storuky
storuky / 14.js
Last active March 25, 2019 14:55
// С рекурсией (медленно)
const calcSum = list => list.reduce((acc, val) => acc + val, 0);
const cumulativeSum = (list, acc = []) => {
if (!list.length) return acc;
const sum = calcSum(list),
subset = list.slice(0, list.length - 1);
return cumulativeSum(subset, [sum, ...acc]);
const operation = a => b => c => a * b + c;
operation('2')(3)('4')
const { log } = console;
const foo = word => {
const bar = word => setTimeout(() => log(word), word.length)
bar(word);
return bar;
}
@storuky
storuky / transform.js
Last active February 10, 2019 11:27
transform
spread(value) {
return (Math.random() - 0.5) * value * 2
},
transformGeneratePersonObjects(){
// we could do something much smarter with object layout, but let's keep it simple
const { x, y } = this.baseObject.position;
// iterate over our Shareholders array
this.shareholders.forEach(shareholder => {
const position = {
@storuky
storuky / example.js
Last active December 27, 2018 10:29
// api.js
export const GetAllProjects = () => Vue.http.get('/swage/v1/projects')
// resources/Project.js
import Vue from 'vue';
export default Vue.resource(
"swage/v1/projects{/id}",
// api.js
export const GetAllProjects = () => Vue.http.get('/swage/v1/projects')
// resources/Project.js
import Vue from 'vue';
export default Vue.resource(
"v1/projects{/id}",