adjust prettier options and prevent looping twice

This commit is contained in:
Sean Yesmunt 2018-10-26 14:08:05 -04:00
parent eec073b25c
commit 9818000e3d
3 changed files with 81 additions and 75 deletions

View file

@ -1,5 +1,6 @@
{
"trailingComma": "es5",
"printWidth": 100,
"singleQuote": true
}
"singleQuote": true,
"arrowParens": "always"
}

View file

@ -40,11 +40,11 @@ reducers[ACTIONS.RESOLVE_URIS_COMPLETED] = (state, action) => {
byId,
claimsByUri: byUri,
channelClaimCounts,
resolvingUris: (state.resolvingUris || []).filter(uri => !resolveInfo[uri]),
resolvingUris: (state.resolvingUris || []).filter((uri) => !resolveInfo[uri]),
});
};
reducers[ACTIONS.FETCH_CLAIM_LIST_MINE_STARTED] = state =>
reducers[ACTIONS.FETCH_CLAIM_LIST_MINE_STARTED] = (state) =>
Object.assign({}, state, {
isFetchingClaimListMine: true,
});
@ -54,18 +54,20 @@ reducers[ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED] = (state, action) => {
const byId = Object.assign({}, state.byId);
const pendingById = Object.assign({}, state.pendingById);
claims.filter(claim => claim.type && claim.type.match(/claim|update/)).forEach(claim => {
if (claim.confirmations < 1) {
pendingById[claim.claim_id] = claim;
} else {
byId[claim.claim_id] = claim;
claims.forEach((claim) => {
if (claim.type && claim.type.match(/claim|update/)) {
if (claim.confirmations < 1) {
pendingById[claim.claim_id] = claim;
} else {
byId[claim.claim_id] = claim;
}
}
});
// Remove old pending publishes
Object.values(pendingById)
.filter(pendingClaim => byId[pendingClaim.claim_id])
.forEach(pendingClaim => {
.filter((pendingClaim) => byId[pendingClaim.claim_id])
.forEach((pendingClaim) => {
delete pendingById[pendingClaim.claim_id];
});
@ -77,7 +79,7 @@ reducers[ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED] = (state, action) => {
});
};
reducers[ACTIONS.FETCH_CHANNEL_LIST_STARTED] = state =>
reducers[ACTIONS.FETCH_CHANNEL_LIST_STARTED] = (state) =>
Object.assign({}, state, { fetchingMyChannels: true });
reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => {
@ -85,7 +87,7 @@ reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => {
const myChannelClaims = new Set(state.myChannelClaims);
const byId = Object.assign({}, state.byId);
claims.forEach(claim => {
claims.forEach((claim) => {
myChannelClaims.add(claim.claim_id);
byId[claim.claim_id] = claim;
});
@ -120,7 +122,7 @@ reducers[ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED] = (state, action) => {
const claimsByUri = Object.assign({}, state.claimsByUri);
if (claims !== undefined) {
claims.forEach(claim => {
claims.forEach((claim) => {
allClaimIds.add(claim.claim_id);
currentPageClaimIds.push(claim.claim_id);
byId[claim.claim_id] = claim;
@ -157,7 +159,7 @@ reducers[ACTIONS.ABANDON_CLAIM_SUCCEEDED] = (state, action) => {
const byId = Object.assign({}, state.byId);
const claimsByUri = Object.assign({}, state.claimsByUri);
Object.keys(claimsByUri).forEach(uri => {
Object.keys(claimsByUri).forEach((uri) => {
if (claimsByUri[uri] === claimId) {
delete claimsByUri[uri];
}
@ -185,7 +187,7 @@ reducers[ACTIONS.CREATE_CHANNEL_COMPLETED] = (state, action) => {
});
};
reducers[ACTIONS.FETCH_FEATURED_CONTENT_STARTED] = state =>
reducers[ACTIONS.FETCH_FEATURED_CONTENT_STARTED] = (state) =>
Object.assign({}, state, {
fetchingFeaturedContent: true,
});
@ -200,7 +202,7 @@ reducers[ACTIONS.FETCH_FEATURED_CONTENT_COMPLETED] = (state, action) => {
});
};
reducers[ACTIONS.FETCH_TRENDING_CONTENT_STARTED] = state =>
reducers[ACTIONS.FETCH_TRENDING_CONTENT_STARTED] = (state) =>
Object.assign({}, state, {
fetchingTrendingContent: true,
});
@ -221,7 +223,7 @@ reducers[ACTIONS.RESOLVE_URIS_STARTED] = (state, action) => {
const oldResolving = state.resolvingUris || [];
const newResolving = Object.assign([], oldResolving);
uris.forEach(uri => {
uris.forEach((uri) => {
if (!newResolving.includes(uri)) {
newResolving.push(uri);
}

View file

@ -4,15 +4,15 @@ import { selectSearchUrisByQuery } from 'redux/selectors/search';
import { createSelector } from 'reselect';
import { isClaimNsfw } from 'util/claim';
const selectState = state => state.claims || {};
const selectState = (state) => state.claims || {};
export const selectClaimsById = createSelector(selectState, state => state.byId || {});
export const selectClaimsById = createSelector(selectState, (state) => state.byId || {});
export const selectClaimsByUri = createSelector(selectState, selectClaimsById, (state, byId) => {
const byUri = state.claimsByUri || {};
const claims = {};
Object.keys(byUri).forEach(uri => {
Object.keys(byUri).forEach((uri) => {
const claimId = byUri[uri];
// NOTE returning a null claim allows us to differentiate between an
@ -30,28 +30,28 @@ export const selectClaimsByUri = createSelector(selectState, selectClaimsById, (
export const selectAllClaimsByChannel = createSelector(
selectState,
state => state.claimsByChannel || {}
(state) => state.claimsByChannel || {}
);
export const selectPendingById = createSelector(selectState, state => state.pendingById);
export const selectPendingById = createSelector(selectState, (state) => state.pendingById);
export const selectPendingClaims = createSelector(selectState, state =>
export const selectPendingClaims = createSelector(selectState, (state) =>
Object.values(state.pendingById || {})
);
export const makeSelectClaimIsPending = uri =>
createSelector(selectPendingById, pendingById => {
export const makeSelectClaimIsPending = (uri) =>
createSelector(selectPendingById, (pendingById) => {
const { claimId } = parseURI(uri);
return Boolean(pendingById[claimId]);
});
export const makeSelectPendingByUri = uri =>
createSelector(selectPendingById, pendingById => {
export const makeSelectPendingByUri = (uri) =>
createSelector(selectPendingById, (pendingById) => {
const { claimId } = parseURI(uri);
return pendingById[claimId];
});
export const makeSelectClaimForUri = uri =>
export const makeSelectClaimForUri = (uri) =>
createSelector(selectClaimsByUri, selectPendingById, (byUri, pendingById) => {
// Check if a claim is pending first
// It won't be in claimsByUri because resolving it will return nothing
@ -64,9 +64,9 @@ export const makeSelectClaimForUri = uri =>
return byUri && byUri[normalizeURI(uri)];
});
export const selectMyClaimsRaw = createSelector(selectState, state => state.myClaims);
export const selectMyClaimsRaw = createSelector(selectState, (state) => state.myClaims);
export const selectAbandoningIds = createSelector(selectState, state =>
export const selectAbandoningIds = createSelector(selectState, (state) =>
Object.keys(state.abandoningById || {})
);
@ -77,12 +77,12 @@ export const selectMyActiveClaims = createSelector(
new Set(
claims &&
claims
.map(claim => claim.claim_id)
.filter(claimId => Object.keys(abandoningIds).indexOf(claimId) === -1)
.map((claim) => claim.claim_id)
.filter((claimId) => Object.keys(abandoningIds).indexOf(claimId) === -1)
)
);
export const makeSelectClaimIsMine = rawUri => {
export const makeSelectClaimIsMine = (rawUri) => {
const uri = normalizeURI(rawUri);
return createSelector(
selectClaimsByUri,
@ -94,11 +94,11 @@ export const makeSelectClaimIsMine = rawUri => {
export const selectAllFetchingChannelClaims = createSelector(
selectState,
state => state.fetchingChannelClaims || {}
(state) => state.fetchingChannelClaims || {}
);
export const makeSelectFetchingChannelClaims = uri =>
createSelector(selectAllFetchingChannelClaims, fetching => fetching && fetching[uri]);
export const makeSelectFetchingChannelClaims = (uri) =>
createSelector(selectAllFetchingChannelClaims, (fetching) => fetching && fetching[uri]);
export const makeSelectClaimsInChannelForPage = (uri, page) =>
createSelector(selectClaimsById, selectAllClaimsByChannel, (byId, allClaims) => {
@ -107,10 +107,10 @@ export const makeSelectClaimsInChannelForPage = (uri, page) =>
if (!claimIds) return claimIds;
return claimIds.map(claimId => byId[claimId]);
return claimIds.map((claimId) => byId[claimId]);
});
export const makeSelectClaimsInChannelForCurrentPage = uri => {
export const makeSelectClaimsInChannelForCurrentPage = (uri) => {
const pageSelector = makeSelectCurrentParam('page');
return createSelector(
@ -123,30 +123,30 @@ export const makeSelectClaimsInChannelForCurrentPage = uri => {
if (!claimIds) return claimIds;
return claimIds.map(claimId => byId[claimId]);
return claimIds.map((claimId) => byId[claimId]);
}
);
};
export const makeSelectMetadataForUri = uri =>
createSelector(makeSelectClaimForUri(uri), claim => {
export const makeSelectMetadataForUri = (uri) =>
createSelector(makeSelectClaimForUri(uri), (claim) => {
const metadata = claim && claim.value && claim.value.stream && claim.value.stream.metadata;
return metadata || (claim === undefined ? undefined : null);
});
export const makeSelectTitleForUri = uri =>
createSelector(makeSelectMetadataForUri(uri), metadata => metadata && metadata.title);
export const makeSelectTitleForUri = (uri) =>
createSelector(makeSelectMetadataForUri(uri), (metadata) => metadata && metadata.title);
export const makeSelectContentTypeForUri = uri =>
createSelector(makeSelectClaimForUri(uri), claim => {
export const makeSelectContentTypeForUri = (uri) =>
createSelector(makeSelectClaimForUri(uri), (claim) => {
const source = claim && claim.value && claim.value.stream && claim.value.stream.source;
return source ? source.contentType : undefined;
});
export const selectIsFetchingClaimListMine = createSelector(
selectState,
state => state.isFetchingClaimListMine
(state) => state.isFetchingClaimListMine
);
export const selectMyClaims = createSelector(
@ -157,7 +157,7 @@ export const selectMyClaims = createSelector(
(myClaimIds, byId, abandoningIds, pendingClaims) => {
const claims = [];
myClaimIds.forEach(id => {
myClaimIds.forEach((id) => {
const claim = byId[id];
if (claim && abandoningIds.indexOf(id) === -1) claims.push(claim);
@ -167,27 +167,27 @@ export const selectMyClaims = createSelector(
}
);
export const selectMyClaimsWithoutChannels = createSelector(selectMyClaims, myClaims =>
myClaims.filter(claim => !claim.name.match(/^@/))
export const selectMyClaimsWithoutChannels = createSelector(selectMyClaims, (myClaims) =>
myClaims.filter((claim) => !claim.name.match(/^@/))
);
export const selectAllMyClaimsByOutpoint = createSelector(
selectMyClaimsRaw,
claims =>
new Set(claims && claims.length ? claims.map(claim => `${claim.txid}:${claim.nout}`) : null)
(claims) =>
new Set(claims && claims.length ? claims.map((claim) => `${claim.txid}:${claim.nout}`) : null)
);
export const selectMyClaimsOutpoints = createSelector(selectMyClaims, myClaims => {
export const selectMyClaimsOutpoints = createSelector(selectMyClaims, (myClaims) => {
const outpoints = [];
myClaims.forEach(claim => outpoints.push(`${claim.txid}:${claim.nout}`));
myClaims.forEach((claim) => outpoints.push(`${claim.txid}:${claim.nout}`));
return outpoints;
});
export const selectFetchingMyChannels = createSelector(
selectState,
state => state.fetchingMyChannels
(state) => state.fetchingMyChannels
);
export const selectMyChannelClaims = createSelector(
@ -197,7 +197,7 @@ export const selectMyChannelClaims = createSelector(
const ids = state.myChannelClaims || [];
const claims = [];
ids.forEach(id => {
ids.forEach((id) => {
if (byId[id]) {
// I'm not sure why this check is necessary, but it ought to be a quick fix for https://github.com/lbryio/lbry-desktop/issues/544
claims.push(byId[id]);
@ -208,46 +208,49 @@ export const selectMyChannelClaims = createSelector(
}
);
export const selectResolvingUris = createSelector(selectState, state => state.resolvingUris || []);
export const selectResolvingUris = createSelector(
selectState,
(state) => state.resolvingUris || []
);
export const makeSelectIsUriResolving = uri =>
export const makeSelectIsUriResolving = (uri) =>
createSelector(
selectResolvingUris,
resolvingUris => resolvingUris && resolvingUris.indexOf(uri) !== -1
(resolvingUris) => resolvingUris && resolvingUris.indexOf(uri) !== -1
);
export const selectFeaturedUris = createSelector(selectState, state => state.featuredUris);
export const selectFeaturedUris = createSelector(selectState, (state) => state.featuredUris);
export const selectFetchingFeaturedUris = createSelector(
selectState,
state => state.fetchingFeaturedContent
(state) => state.fetchingFeaturedContent
);
export const selectTrendingUris = createSelector(selectState, state => state.trendingUris);
export const selectTrendingUris = createSelector(selectState, (state) => state.trendingUris);
export const selectFetchingTrendingUris = createSelector(
selectState,
state => state.fetchingTrendingContent
(state) => state.fetchingTrendingContent
);
export const selectPlayingUri = createSelector(selectState, state => state.playingUri);
export const selectPlayingUri = createSelector(selectState, (state) => state.playingUri);
export const selectChannelClaimCounts = createSelector(
selectState,
state => state.channelClaimCounts || {}
(state) => state.channelClaimCounts || {}
);
export const makeSelectTotalItemsForChannel = uri =>
createSelector(selectChannelClaimCounts, byUri => byUri && byUri[uri]);
export const makeSelectTotalItemsForChannel = (uri) =>
createSelector(selectChannelClaimCounts, (byUri) => byUri && byUri[uri]);
export const makeSelectTotalPagesForChannel = uri =>
export const makeSelectTotalPagesForChannel = (uri) =>
createSelector(
selectChannelClaimCounts,
byUri => byUri && byUri[uri] && Math.ceil(byUri[uri] / 10)
(byUri) => byUri && byUri[uri] && Math.ceil(byUri[uri] / 10)
);
export const makeSelectNsfwCountFromUris = uris =>
createSelector(selectClaimsByUri, claims =>
export const makeSelectNsfwCountFromUris = (uris) =>
createSelector(selectClaimsByUri, (claims) =>
uris.reduce((acc, uri) => {
const claim = claims[uri];
if (isClaimNsfw(claim)) {
@ -257,7 +260,7 @@ export const makeSelectNsfwCountFromUris = uris =>
}, 0)
);
export const makeSelectNsfwCountForChannel = uri => {
export const makeSelectNsfwCountForChannel = (uri) => {
const pageSelector = makeSelectCurrentParam('page');
return createSelector(
@ -281,7 +284,7 @@ export const makeSelectNsfwCountForChannel = uri => {
);
};
export const makeSelectRecommendedContentForUri = uri =>
export const makeSelectRecommendedContentForUri = (uri) =>
createSelector(
makeSelectClaimForUri(uri),
selectSearchUrisByQuery,
@ -305,7 +308,7 @@ export const makeSelectRecommendedContentForUri = uri =>
searchUris = searchUris.slice(1);
}
searchUris = searchUris.filter(searchUri => searchUri !== uri);
searchUris = searchUris.filter((searchUri) => searchUri !== uri);
recommendedContent = searchUris;
}
}
@ -316,7 +319,7 @@ export const makeSelectRecommendedContentForUri = uri =>
// Returns the associated channel uri for a given claim uri
export const makeSelectChannelForClaimUri = (uri, includePrefix = false) =>
createSelector(makeSelectClaimForUri(uri), claim => {
createSelector(makeSelectClaimForUri(uri), (claim) => {
if (!claim) {
return null;
}