@trycourier/react-provider 1.22.2-internal.d598d2d.0 → 1.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,71 +5,75 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports["default"] = void 0;
7
7
 
8
+ var _react = require("react");
9
+
8
10
  var _clientGraphql = require("@trycourier/client-graphql");
9
11
 
10
12
  var useCourierActions = function useCourierActions(state, dispatch) {
11
- var courierClient = (0, _clientGraphql.createCourierClient)({
12
- apiUrl: state.apiUrl,
13
- clientKey: state.clientKey,
14
- userId: state.userId,
15
- userSignature: state.userSignature
16
- });
17
- var brands = (0, _clientGraphql.Brands)({
18
- client: courierClient
19
- });
20
- var events = (0, _clientGraphql.Events)({
21
- client: courierClient
22
- });
23
- return {
24
- init: function init(payload) {
25
- dispatch({
26
- type: "root/INIT",
27
- payload: payload
28
- });
29
- },
30
- initToast: function initToast(payload) {
31
- dispatch({
32
- type: "toast/INIT",
33
- payload: payload
34
- });
35
- },
36
- initInbox: function initInbox(payload) {
37
- dispatch({
38
- type: "inbox/INIT",
39
- payload: payload
40
- });
41
- },
42
- getBrand: function getBrand(brandId) {
43
- dispatch({
44
- type: "root/GET_BRAND",
45
- payload: function payload() {
46
- return brands.getBrand(brandId);
47
- }
48
- });
49
- },
50
- setBrand: function setBrand(brand) {
51
- dispatch({
52
- type: "root/GET_BRAND/DONE",
53
- payload: brand
54
- });
55
- },
56
- createTrackEvent: function createTrackEvent(trackingId) {
57
- dispatch({
58
- type: "CREATE_TRACKING_EVENT",
59
- payload: function payload() {
60
- return events.trackEvent(trackingId);
61
- }
62
- });
63
- },
64
- createBatchTrackEvent: function createBatchTrackEvent(eventType) {
65
- dispatch({
66
- type: "CREATE_TRACKING_EVENT_BATCH",
67
- payload: function payload() {
68
- return events.trackEventBatch(eventType);
69
- }
70
- });
71
- }
72
- };
13
+ return (0, _react.useMemo)(function () {
14
+ var courierClient = (0, _clientGraphql.createCourierClient)({
15
+ apiUrl: state.apiUrl,
16
+ clientKey: state.clientKey,
17
+ userId: state.userId,
18
+ userSignature: state.userSignature
19
+ });
20
+ var brands = (0, _clientGraphql.Brands)({
21
+ client: courierClient
22
+ });
23
+ var events = (0, _clientGraphql.Events)({
24
+ client: courierClient
25
+ });
26
+ return {
27
+ init: function init(payload) {
28
+ dispatch({
29
+ type: "root/INIT",
30
+ payload: payload
31
+ });
32
+ },
33
+ initToast: function initToast(payload) {
34
+ dispatch({
35
+ type: "toast/INIT",
36
+ payload: payload
37
+ });
38
+ },
39
+ initInbox: function initInbox(payload) {
40
+ dispatch({
41
+ type: "inbox/INIT",
42
+ payload: payload
43
+ });
44
+ },
45
+ getBrand: function getBrand(brandId) {
46
+ dispatch({
47
+ type: "root/GET_BRAND",
48
+ payload: function payload() {
49
+ return brands.getBrand(brandId);
50
+ }
51
+ });
52
+ },
53
+ setBrand: function setBrand(brand) {
54
+ dispatch({
55
+ type: "root/GET_BRAND/DONE",
56
+ payload: brand
57
+ });
58
+ },
59
+ createTrackEvent: function createTrackEvent(trackingId) {
60
+ dispatch({
61
+ type: "CREATE_TRACKING_EVENT",
62
+ payload: function payload() {
63
+ return events.trackEvent(trackingId);
64
+ }
65
+ });
66
+ },
67
+ createBatchTrackEvent: function createBatchTrackEvent(eventType) {
68
+ dispatch({
69
+ type: "CREATE_TRACKING_EVENT_BATCH",
70
+ payload: function payload() {
71
+ return events.trackEventBatch(eventType);
72
+ }
73
+ });
74
+ }
75
+ };
76
+ }, [state.apiUrl, state.clientKey, state.userId, state.userSignature]);
73
77
  };
74
78
 
75
79
  var _default = useCourierActions;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.useWhyDidYouUpdate = useWhyDidYouUpdate;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _react = require("react");
13
+
14
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
15
+
16
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
17
+
18
+ function useWhyDidYouUpdate(name, props) {
19
+ // Get a mutable ref object where we can store props ...
20
+ // ... for comparison next time this hook runs.
21
+ var previousProps = (0, _react.useRef)({});
22
+ (0, _react.useEffect)(function () {
23
+ if (previousProps.current) {
24
+ var _previousProps$curren;
25
+
26
+ // Get all keys from previous and current props
27
+ var allKeys = Object.keys(_objectSpread(_objectSpread({}, (_previousProps$curren = previousProps.current) !== null && _previousProps$curren !== void 0 ? _previousProps$curren : {}), props)); // Use this object to keep track of changed props
28
+
29
+ var changesObj = {}; // Iterate through keys
30
+
31
+ allKeys.forEach(function (key) {
32
+ var _previousProps$curren2;
33
+
34
+ // If previous is different from current
35
+ if ((previousProps === null || previousProps === void 0 ? void 0 : (_previousProps$curren2 = previousProps.current) === null || _previousProps$curren2 === void 0 ? void 0 : _previousProps$curren2[key]) !== props[key]) {
36
+ var _previousProps$curren3;
37
+
38
+ // Add to changesObj
39
+ changesObj[key] = {
40
+ from: previousProps === null || previousProps === void 0 ? void 0 : (_previousProps$curren3 = previousProps.current) === null || _previousProps$curren3 === void 0 ? void 0 : _previousProps$curren3[key],
41
+ to: props[key]
42
+ };
43
+ }
44
+ }); // If changesObj not empty then output to console
45
+
46
+ if (Object.keys(changesObj).length) {
47
+ console.log("[why-did-you-update]", name, changesObj);
48
+ }
49
+ } // Finally update previousProps with current props for next hook call
50
+
51
+
52
+ previousProps.current = props;
53
+ });
54
+ }
package/dist/index.js CHANGED
@@ -157,7 +157,7 @@ var CourierProvider = function CourierProvider(_ref) {
157
157
  return function () {
158
158
  courierTransport.unsubscribe(userId);
159
159
  };
160
- }, [transport, userId]);
160
+ }, [actions, transport, userId]);
161
161
  (0, _react.useEffect)(function () {
162
162
  if (!_transport && (!clientKey || !userId)) {
163
163
  return;
@@ -171,15 +171,19 @@ var CourierProvider = function CourierProvider(_ref) {
171
171
  userId: userId,
172
172
  userSignature: userSignature
173
173
  });
174
- }, [apiUrl, clientKey, transport, userId, userSignature, brandId]);
174
+ }, [actions, apiUrl, clientKey, transport, userId, userSignature, brandId]);
175
175
  (0, _react.useEffect)(function () {
176
176
  if (brand) {
177
177
  // if we pass in brand, don't fetch it
178
178
  return;
179
179
  }
180
180
 
181
+ if (!clientKey || !userId) {
182
+ return;
183
+ }
184
+
181
185
  actions.getBrand(brandId);
182
- }, [brand, brandId]);
186
+ }, [actions, brand, brandId, clientKey, userId]);
183
187
  (0, _react.useEffect)(function () {
184
188
  if (!state.brand || !clientKey || !userId) {
185
189
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/react-provider",
3
- "version": "1.22.2-internal.d598d2d.0+d598d2d",
3
+ "version": "1.24.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "typings/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
- "@trycourier/client-graphql": "^1.22.2-internal.d598d2d.0+d598d2d",
18
+ "@trycourier/client-graphql": "^1.24.1",
19
19
  "buffer": "^6.0.3",
20
20
  "graphql": "^15.5.0",
21
21
  "react-use": "^17.2.1",
@@ -31,5 +31,5 @@
31
31
  "dist/",
32
32
  "typings/"
33
33
  ],
34
- "gitHead": "d598d2dead1d18540c8f36afec9c4d5466f1551a"
34
+ "gitHead": "0c42a5155afb20eea44e1788c305b2e68e49fc52"
35
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"use-courier-actions.d.ts","sourceRoot":"","sources":["../../src/hooks/use-courier-actions.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,iBAAiB;;;;;;;;CAuDtB,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
1
+ {"version":3,"file":"use-courier-actions.d.ts","sourceRoot":"","sources":["../../src/hooks/use-courier-actions.ts"],"names":[],"mappings":"AAQA,QAAA,MAAM,iBAAiB;;;;;;;;CAyDtB,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function useWhyDidYouUpdate(name: any, props: any): void;
2
+ //# sourceMappingURL=use-why-did-you-update.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-why-did-you-update.d.ts","sourceRoot":"","sources":["../../src/hooks/use-why-did-you-update.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAAC,IAAI,KAAA,EAAE,KAAK,KAAA,QAgC7C"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAOA,OAAO,KAA0C,MAAM,OAAO,CAAC;AAE/D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,KAAK,EACL,SAAS,EACV,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAI/E,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AAExB,eAAO,MAAM,eAAe,oCAAmB,CAAC;AAEhD,YAAY,EACV,KAAK,EACL,SAAS,EACT,UAAU,EACV,YAAY,EACZ,eAAe,EACf,eAAe,GAChB,CAAC;AAEF,eAAO,MAAM,cAAc,4CAE1B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,iBAAiB,CAAC,qBAAqB,CAmJ1E,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAOA,OAAO,KAA0C,MAAM,OAAO,CAAC;AAE/D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,KAAK,EACL,SAAS,EACV,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAI/E,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AAExB,eAAO,MAAM,eAAe,oCAAmB,CAAC;AAEhD,YAAY,EACV,KAAK,EACL,SAAS,EACT,UAAU,EACV,YAAY,EACZ,eAAe,EACf,eAAe,GAChB,CAAC;AAEF,eAAO,MAAM,cAAc,4CACkC,CAAC;AAE9D,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,iBAAiB,CAAC,qBAAqB,CAwJxE,CAAC"}