<commit_before>/**
 * `core/user` data store: feature tours
 *
 * Site Kit by Google, Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * External dependencies
 */
import compareVersions from 'compare-versions';
import invariant from 'invariant';

/**
 * Internal dependencies
 */
import API from 'googlesitekit-api';
import Data from 'googlesitekit-data';
import { createFetchStore } from '../../data/create-fetch-store';
import { STORE_NAME } from './constants';
import featureTours from '../../../feature-tours';
const { createRegistrySelector, createRegistryControl } = Data;
const { getRegistry } = Data.commonActions;

// Actions.
const DISMISS_TOUR = 'DISMISS_TOUR';
const RECEIVE_READY_TOURS = 'RECEIVE_READY_TOURS';
const RECEIVE_TOURS = 'RECEIVE_TOURS';
const CHECK_TOUR_REQUIREMENTS = 'CHECK_TOUR_REQUIREMENTS';

const fetchGetDismissedToursStore = createFetchStore( {
	baseName: 'getDismissedTours',
	controlCallback: () => {
		return API.get( 'core', 'user', 'dismissed-tours', {}, { useCache: false } );
	},
	reducerCallback: ( state, dismissedTours ) => {
		return {
			...state,
			dismissedTours,
		};
	},
} );
const { fetchGetDismissedTours } = fetchGetDismissedToursStore.actions;
const fetchDismissTourStore = createFetchStore( {
	baseName: 'dismissTour',
	controlCallback: ( { slug } ) => API.set( 'core', 'user', 'dismiss-tour', { slug } ),
	reducerCallback: ( state, dismissedTours ) => {
		return {
			...state,
			dismissedTours,
		};
	},
	argsToParams: ( slug ) => ( { slug } ),
	validateParams: ( { slug } = {} ) => {
		invariant( slug, 'slug is required.' );
	},
} );
const { fetchDismissTour } = fetchDismissTourStore.actions;

const baseInitialState = {
	// Array of dismissed tour slugs.
	dismissedTours: undefined,
	// Array of tour objects.
	tours: featureTours,
	// Map of [viewContext]: ordered array of tour objects.
	readyTours: {},
};

const baseActions = {
	/**
	 * Dismisses the given tour by slug.
	 *
	 * @since 1.27.0
	 *
	 * @param {string} slug Tour slug to dismiss.
	 * @return {Object} Generator instance.
	 */
	dismissTour( slug ) {
		invariant( slug, 'A tour slug is required to dismiss a tour.' );

		return ( function* () {
			const { select } = yield getRegistry();
			if ( select( STORE_NAME ).isTourDismissed( slug ) ) {
				const response = select( STORE_NAME ).getDismissedTours();
				return { response, error: undefined };
			}
			// Dismiss the given tour immediately.
			yield {
				payload: { slug },
				type: DISMISS_TOUR,
			};<commit_msg>Use isFetchingDismissTour instead of isTourDismissed to avoid extra fetch.<commit_after>/**
 * `core/user` data store: feature tours
 *
 * Site Kit by Google, Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * External dependencies
 */
import compareVersions from 'compare-versions';
import invariant from 'invariant';

/**
 * Internal dependencies
 */
import API from 'googlesitekit-api';
import Data from 'googlesitekit-data';
import { createFetchStore } from '../../data/create-fetch-store';
import { STORE_NAME } from './constants';
import featureTours from '../../../feature-tours';
const { createRegistrySelector, createRegistryControl } = Data;
const { getRegistry } = Data.commonActions;

// Actions.
const DISMISS_TOUR = 'DISMISS_TOUR';
const RECEIVE_READY_TOURS = 'RECEIVE_READY_TOURS';
const RECEIVE_TOURS = 'RECEIVE_TOURS';
const CHECK_TOUR_REQUIREMENTS = 'CHECK_TOUR_REQUIREMENTS';

const fetchGetDismissedToursStore = createFetchStore( {
	baseName: 'getDismissedTours',
	controlCallback: () => {
		return API.get( 'core', 'user', 'dismissed-tours', {}, { useCache: false } );
	},
	reducerCallback: ( state, dismissedTours ) => {
		return {
			...state,
			dismissedTours,
		};
	},
} );
const { fetchGetDismissedTours } = fetchGetDismissedToursStore.actions;
const fetchDismissTourStore = createFetchStore( {
	baseName: 'dismissTour',
	controlCallback: ( { slug } ) => API.set( 'core', 'user', 'dismiss-tour', { slug } ),
	reducerCallback: ( state, dismissedTours ) => {
		return {
			...state,
			dismissedTours,
		};
	},
	argsToParams: ( slug ) => ( { slug } ),
	validateParams: ( { slug } = {} ) => {
		invariant( slug, 'slug is required.' );
	},
} );
const { fetchDismissTour } = fetchDismissTourStore.actions;

const baseInitialState = {
	// Array of dismissed tour slugs.
	dismissedTours: undefined,
	// Array of tour objects.
	tours: featureTours,
	// Map of [viewContext]: ordered array of tour objects.
	readyTours: {},
};

const baseActions = {
	/**
	 * Dismisses the given tour by slug.
	 *
	 * @since 1.27.0
	 *
	 * @param {string} slug Tour slug to dismiss.
	 * @return {Object} Generator instance.
	 */
	dismissTour( slug ) {
		invariant( slug, 'A tour slug is required to dismiss a tour.' );

		return ( function* () {
			const { select } = yield getRegistry();
			if ( select( STORE_NAME ).isFetchingDismissTour( slug ) ) {
				const response = select( STORE_NAME ).getDismissedTours();
				return { response, error: undefined };
			}
			// Dismiss the given tour immediately.
			yield {
				payload: { slug },
				type: DISMISS_TOUR,
			};
{'fraction_non_alphanumeric': 0.12672399805289633, 'fraction_numerical': 0.0038942073665422685, 'mean_word_length': 3.853543307086614, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '10266', 'n_tokens_mistral': 2069, 'n_tokens_neox': 1878, 'n_words': 578}