Skip to content

Commit

Permalink
Access interaction-tracking API through React.unstable_interactions
Browse files Browse the repository at this point in the history
1. For CJS bundles, this will just re-export the interaction-tracking package but for UMD builds, it will inline the functionality to avoid breaking backwards compatibility.
2. All new interaction-tracking APIs are tagged as unstabled (e.g. React.unstable_interactions.wrap, import { unstable_track } from 'interaction-tracking')
  • Loading branch information
Brian Vaughn committed Aug 29, 2018
1 parent 3021a81 commit 17d0f06
Show file tree
Hide file tree
Showing 18 changed files with 416 additions and 333 deletions.
5 changes: 3 additions & 2 deletions fixtures/unstable-async/suspense/src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {track, wrap} from 'interaction-tracking';
import React, {Placeholder, PureComponent} from 'react';
import React, {Placeholder, PureComponent, unstable_interactions} from 'react';
import {createResource} from 'simple-cache-provider';
import {cache} from '../cache';
import Spinner from './Spinner';
import ContributorListPage from './ContributorListPage';

const {track, wrap} = unstable_interactions;

const UserPageResource = createResource(() => import('./UserPage'));

function UserPageLoader(props) {
Expand Down
5 changes: 3 additions & 2 deletions fixtures/unstable-async/suspense/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {track} from 'interaction-tracking';
import React, {Fragment, PureComponent} from 'react';
import React, {Fragment, PureComponent, unstable_interactions} from 'react';
import {unstable_createRoot, render} from 'react-dom';
import {cache} from './cache';
import {
Expand All @@ -12,6 +11,8 @@ import App from './components/App';
import Draggable from 'react-draggable';
import './index.css';

const {track} = unstable_interactions;

let handleReset;

class Shell extends PureComponent {
Expand Down
21 changes: 18 additions & 3 deletions fixtures/unstable-async/suspense/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3483,7 +3483,11 @@ inquirer@3.3.0, inquirer@^3.0.6:
through "^2.3.6"

interaction-tracking@../../../build/node_modules/interaction-tracking:
version "16.4.3-alpha.0"

interaction-tracking@16.4.3-alpha.0:
version "0.0.1"
resolved "https://registry.yarnpkg.com/interaction-tracking/-/interaction-tracking-0.0.1.tgz#08877accb2ec479f2af83d7de7a9ae60b80e8dc5"

internal-ip@1.2.0:
version "1.2.0"
Expand Down Expand Up @@ -4102,6 +4106,10 @@ js-tokens@^3.0.0, js-tokens@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"

"js-tokens@^3.0.0 || ^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"

js-yaml@^3.4.3, js-yaml@^3.7.0, js-yaml@^3.9.1:
version "3.10.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.10.0.tgz#2e78441646bd4682e963f22b6e92823c309c62dc"
Expand Down Expand Up @@ -4389,12 +4397,18 @@ longest@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"

loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.3.1:
loose-envify@^1.0.0, loose-envify@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.1.tgz#d1a8ad33fa9ce0e713d65fdd0ac8b748d478c848"
dependencies:
js-tokens "^3.0.0"

loose-envify@^1.1.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
dependencies:
js-tokens "^3.0.0 || ^4.0.0"

loud-rejection@^1.0.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/loud-rejection/-/loud-rejection-1.6.0.tgz#5b46f80147edee578870f086d04821cf998e551f"
Expand Down Expand Up @@ -5720,7 +5734,7 @@ react-dev-utils@^5.0.1:
text-table "0.2.0"

react-dom@../../../build/node_modules/react-dom:
version "16.4.1"
version "16.4.3-alpha.0"
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
Expand Down Expand Up @@ -5783,8 +5797,9 @@ react-scripts@^1.1.4:
fsevents "^1.1.3"

react@../../../build/node_modules/react:
version "16.4.1"
version "16.4.3-alpha.0"
dependencies:
interaction-tracking "16.4.3-alpha.0"
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
Expand Down
7 changes: 7 additions & 0 deletions packages/interaction-tracking/npm/subscriptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/interaction-tracking-subscriptions.production.min.js');
} else {
module.exports = require('./cjs/interaction-tracking-subscriptions.development.js');
}
2 changes: 1 addition & 1 deletion packages/interaction-tracking/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "interaction-tracking",
"description": "utility for tracking interaction events",
"version": "0.0.1",
"version": "16.4.3-alpha.0",
"license": "MIT",
"files": [
"LICENSE",
Expand Down
10 changes: 5 additions & 5 deletions packages/interaction-tracking/src/InteractionTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ if (enableInteractionTracking) {
// They should not typically be accessed directly.
export {interactionsRef as __interactionsRef, subscriberRef as __subscriberRef};

export function clear(callback: Function): any {
export function unstable_clear(callback: Function): any {
if (!enableInteractionTracking) {
return callback();
}
Expand All @@ -98,19 +98,19 @@ export function clear(callback: Function): any {
}
}

export function getCurrent(): Set<Interaction> | null {
export function unstable_getCurrent(): Set<Interaction> | null {
if (!enableInteractionTracking) {
return null;
} else {
return interactionsRef.current;
}
}

export function getThreadID(): number {
export function unstable_getThreadID(): number {
return ++threadIDCounter;
}

export function track(
export function unstable_track(
name: string,
timestamp: number,
callback: Function,
Expand Down Expand Up @@ -174,7 +174,7 @@ export function track(
return returnValue;
}

export function wrap(
export function unstable_wrap(
callback: Function,
threadID: number = DEFAULT_THREAD_ID,
): Function {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ if (enableInteractionTracking) {
subscribers = new Set();
}

export function subscribe(subscriber: Subscriber): void {
export function unstable_subscribe(subscriber: Subscriber): void {
if (enableInteractionTracking) {
subscribers.add(subscriber);
}
}

export function unsubscribe(subscriber: Subscriber): void {
export function unstable_unsubscribe(subscriber: Subscriber): void {
if (enableInteractionTracking) {
subscribers.delete(subscriber);
}
Expand Down
Loading

0 comments on commit 17d0f06

Please sign in to comment.