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", "trailingComma": "es5",
"printWidth": 100, "printWidth": 100,
"singleQuote": true "singleQuote": true,
} "arrowParens": "always"
}

View file

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

View file

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