const duplicates = Array
.from(arr.reduce((acc, n) => acc.set(n.id, acc.has(n.id)), new Map))
.reduce((acc, n) => (n[1] && acc.push(n[0]), acc), []);
// или
const duplicates = Object
.entries(arr.reduce((acc, n) => (acc[n.id] = (acc[n.id] || 0) + 1, acc), {}))
.filter(n => n[1] > 1)
.map(n => +n[0]);
// или
const duplicates = [...arr
.reduce((acc, n) => (acc[+acc[0].has(n.id)].add(n.id), acc), [ new Set, new Set ])
.pop()
];
// или
const duplicates = arr
.map(n => n.id)
.filter((n, i, a) => i !== a.indexOf(n))
.filter((n, i, a) => i === a.indexOf(n));
// или
const duplicates = arr.reduce((acc, { id: n }, i, a) => (
!acc.includes(n) && i !== a.findIndex(m => m.id === n) && acc.push(n),
acc
), []);
<ui-icon
iconSet="ico-moon"
data-icon="i-more"
@click="stage.show = !stage.show"
>
<div
class="opportunity-board__list"
v-show="stage.show"
>
s-switch(@switch="switch")
this.switch
. row.toggleDetails
в качестве обработчика клика, можно завернуть его в метод, который будет принимать row
и проверять наличие дополнительной информации, инициируя её подгрузку в случае отсутствия. Например (вместо запроса setTimeout, но думаю, что суть ясна). model: {
prop: 'checked',
},
props: {
value: [ String, Number ],
checked: [ Boolean, Array ],
label: String,
disabled: Boolean,
},
computed: {
model: {
get() {
return this.checked;
},
set(val) {
this.$emit('input', val);
},
},
},
<label>
<input
type="checkbox"
v-model="model"
:value="value"
:disabled="disabled"
/>
{{ label }}
</label>
animated: false
на animated: Array(6).fill(false)
.<div
v-for="n in animated"
:class="{ animated: n }"
...
this.$refs.animate.forEach((n, i) => new Waypoint.Inview({
element: n,
entered: () => this.$set(this.animated, i, true),
exited: () => this.$set(this.animated, i, false),
}));
$('.slider').slider('values', [ thisfrom, thisto ]);
const colors = [ 'red', 'orange', 'yellow', 'green', 'aqua', 'blue', 'magenta' ];
let index = -1;
+ 1
и меняете цвет background'а:hoverEl.addEventListener('mouseenter', () => {
index = (index + 1) % colors.length;
colorEl.style.backgroundColor = colors[index];
});
const data = Array
.from(document.querySelectorAll('.js-input input'))
.reduce((acc, n) => {
const keys = n.name.match(/(?<=\[)\w+(?=\])/g);
const key = keys.pop();
keys.reduce((p, c) => p[c] = p[c] || {}, acc)[key] = n.value;
return acc;
}, {});
state: {
wishlistIds: [],
...
plugins: [
createPersistedState({
paths: [ 'wishlistIds' ],
}),
...
getters: {
wishlist: state => state.games.filter(n => state.wishlistIds.includes(n.id)),
...
mutations: {
addGame(state, gameId) {
if (!state.wishlistIds.includes(gameId)) {
state.wishlistIds.push(gameId);
}
},
removeGame(state, gameId) {
const index = state.wishlistIds.indexOf(gameId);
if (index !== -1) {
state.wishlistIds.splice(index, 1);
}
},
...
computed: {
liked: {
get() {
return this.$store.state.wishlistIds.includes(this.game.id);
},
set(val) {
this.$store.commit(val ? 'addGame' : 'removeGame', this.game.id);
},
},
...
<button @click="liked = !liked" :class="{ liked }" class="like"></button>