Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions packages/analytics-core/scripts/types.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
// https://github.com/englercj/tsd-jsdoc/issues/64#issuecomment-462020832
const fs = require('fs')
const path = require('path')
const indentString = require('indent-string')
const mkdirp = require('mkdirp')

// https://github.com/englercj/tsd-jsdoc/issues/64#issuecomment-462020832

const TYPES_PATH = path.resolve(__dirname, '../temp-types/types.d.ts')
// analytics.cjs.d.ts
const OUTPUT_PATH = path.resolve(__dirname, '../lib/types.d.ts')
const content = fs.readFileSync(TYPES_PATH, 'utf-8')

// Export not needed
const exportDeclaration = content.replace(/^(declare function analytics)/gm, 'export function analytics')
const typesFromJsDocs = content
// Remove declares
.replace(/^declare\s/gm, '')
// Make promises return void
.replace(/\@returns \{Promise\}/gm, '@returns {Promise<void>}')
// Fix plugin interface
.replace(/plugins\?: object\[\]/gm, 'plugins?: Array<AnalyticsPlugin>')

// Expose main API
const newContent = `${content}
export const CONSTANTS: constants;
const newContent = `declare module "analytics" {
${indentString(typesFromJsDocs, 2)}
export const CONSTANTS: constants;

export const init = analytics;
export const init: typeof analytics;

export const Analytics = analytics;
export const Analytics: typeof analytics;

export = analytics;`
export = analytics;
}`

mkdirp(path.dirname(OUTPUT_PATH), function (err) {
if (err) console.error(err)
Expand Down
8 changes: 4 additions & 4 deletions packages/analytics-core/src/vendor/redux/createStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FUNC, UNDEF, ACTION_INIT, REDUCER } from './utils/defs'
// eslint-disable-next-line
const $$observable = /* #__PURE__ */ (() => (typeof Symbol === FUNC && Symbol.observable) || '@@observable')();

/**
/*
* Creates a Redux store that holds the state tree.
* The only way to change the data in the store is to call `dispatch()` on it.
*
Expand Down Expand Up @@ -60,7 +60,7 @@ export default function createStore(reducer, preloadedState, enhancer) {
}
}

/**
/*
* Reads the state tree managed by the store.
*
* @returns {any} The current state tree of your application.
Expand All @@ -69,7 +69,7 @@ export default function createStore(reducer, preloadedState, enhancer) {
return currentState
}

/**
/*
* Adds a change listener. It will be called any time an action is dispatched,
* and some part of the state tree may potentially have changed. You may then
* call `getState()` to read the current state tree inside the callback.
Expand Down Expand Up @@ -197,7 +197,7 @@ export default function createStore(reducer, preloadedState, enhancer) {
function observable() {
const outerSubscribe = subscribe
return {
/**
/*
* The minimal observable subscription method.
* @param {Object} observer Any object that can be used as an observer.
* The observer object should have a `next` method.
Expand Down
7 changes: 1 addition & 6 deletions packages/analytics-core/src/vendor/redux/utils/defs.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
export const FUNC = 'function'
export const UNDEF = 'undefined'
export const REDUCER = 'reducer'
/**
* These are private action types reserved by Redux.
* For any unknown actions, you must return the current state.
* If the current state is undefined, you must return the initial state.
* Do not reference these action types directly in your code.
*/

const base = '@@redux/'
export const ACTION_INIT = base + 'INIT'
export const ACTION_TEST = base + Math.random().toString(36)