@knocklabs/client
Advanced tools
Comparing version 0.4.4 to 0.4.5-rc.1
@@ -24,2 +24,4 @@ "use strict"; | ||
var _networkStatus = require("../../networkStatus"); | ||
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; } | ||
@@ -272,3 +274,7 @@ | ||
var options, | ||
_this$store, | ||
setState, | ||
getState, | ||
_getState, | ||
networkStatus, | ||
queryParams, | ||
@@ -286,9 +292,22 @@ result, | ||
options = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : {}; | ||
setState = this.store.setState; | ||
_this$store = this.store, setState = _this$store.setState, getState = _this$store.getState; | ||
_getState = getState(), networkStatus = _getState.networkStatus; // If there's an existing request in flight, then do nothing | ||
if (!(0, _networkStatus.isRequestInFlight)(networkStatus)) { | ||
_context7.next = 5; | ||
break; | ||
} | ||
return _context7.abrupt("return"); | ||
case 5: | ||
// Set the loading type based on the request type it is | ||
setState(function (store) { | ||
return store.setLoading(true); | ||
var _options$__loadingTyp; | ||
return store.setNetworkStatus((_options$__loadingTyp = options.__loadingType) !== null && _options$__loadingTyp !== void 0 ? _options$__loadingTyp : _networkStatus.NetworkStatus.loading); | ||
}); // Always include the default params, if they have been set | ||
queryParams = _objectSpread(_objectSpread({}, this.defaultOptions), options); | ||
_context7.next = 6; | ||
_context7.next = 9; | ||
return this.apiClient.makeRequest({ | ||
@@ -300,7 +319,7 @@ method: "GET", | ||
case 6: | ||
case 9: | ||
result = _context7.sent; | ||
if (!(result.statusCode === "error")) { | ||
_context7.next = 10; | ||
_context7.next = 13; | ||
break; | ||
@@ -310,3 +329,3 @@ } | ||
setState(function (store) { | ||
return store.setLoading(false); | ||
return store.setNetworkStatus(_networkStatus.NetworkStatus.error); | ||
}); | ||
@@ -318,3 +337,3 @@ return _context7.abrupt("return", { | ||
case 10: | ||
case 13: | ||
response = { | ||
@@ -354,3 +373,3 @@ entries: result.body.entries, | ||
case 14: | ||
case 17: | ||
case "end": | ||
@@ -373,3 +392,3 @@ return _context7.stop(); | ||
var _fetchNextPage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8() { | ||
var getState, _getState, pageInfo; | ||
var getState, _getState2, pageInfo; | ||
@@ -382,3 +401,3 @@ return _regenerator["default"].wrap(function _callee8$(_context8) { | ||
getState = this.store.getState; | ||
_getState = getState(), pageInfo = _getState.pageInfo; | ||
_getState2 = getState(), pageInfo = _getState2.pageInfo; | ||
@@ -394,3 +413,4 @@ if (pageInfo.after) { | ||
this.fetch({ | ||
after: pageInfo.after | ||
after: pageInfo.after, | ||
__loadingType: _networkStatus.NetworkStatus.fetchMore | ||
}); | ||
@@ -422,3 +442,3 @@ | ||
var _onNewMessageReceived = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(_ref) { | ||
var metadata, _this$store, getState, setState, currentHead; | ||
var metadata, _this$store2, getState, setState, currentHead; | ||
@@ -431,3 +451,3 @@ return _regenerator["default"].wrap(function _callee9$(_context9) { | ||
// Handle the new message coming in | ||
_this$store = this.store, getState = _this$store.getState, setState = _this$store.setState; | ||
_this$store2 = this.store, getState = _this$store2.getState, setState = _this$store2.setState; | ||
currentHead = getState().items[0]; // Optimistically set the badge counts | ||
@@ -465,5 +485,5 @@ | ||
value: function optimisticallyPerformStatusUpdate(itemOrItems, type, attrs, badgeCountAttr) { | ||
var _this$store2 = this.store, | ||
getState = _this$store2.getState, | ||
setState = _this$store2.setState; | ||
var _this$store3 = this.store, | ||
getState = _this$store3.getState, | ||
setState = _this$store3.setState; | ||
var itemIds = Array.isArray(itemOrItems) ? itemOrItems.map(function (item) { | ||
@@ -474,5 +494,7 @@ return item.id; | ||
if (badgeCountAttr) { | ||
var _getState2 = getState(), | ||
metadata = _getState2.metadata; | ||
var _getState3 = getState(), | ||
metadata = _getState3.metadata; // Tnis is a hack to determine the direction of whether we're | ||
// adding or removing from the badge count | ||
var direction = type.startsWith("un") ? itemIds.length : -itemIds.length; | ||
@@ -479,0 +501,0 @@ setState(function (store) { |
@@ -14,2 +14,4 @@ "use strict"; | ||
var _networkStatus = require("../../networkStatus"); | ||
var _utils = require("./utils"); | ||
@@ -35,3 +37,6 @@ | ||
return { | ||
// Keeps track of all of the items loaded | ||
items: [], | ||
// The network status indicates what's happening with the request | ||
networkStatus: _networkStatus.NetworkStatus.ready, | ||
loading: false, | ||
@@ -50,2 +55,4 @@ // Keeps track of the current badge counts | ||
}, | ||
// TODO: remove this function from the store as we're now using the | ||
// `setNetworkStatus` function to derive this information instead | ||
setLoading: function setLoading(loading) { | ||
@@ -58,2 +65,10 @@ return set(function () { | ||
}, | ||
setNetworkStatus: function setNetworkStatus(networkStatus) { | ||
return set(function () { | ||
return { | ||
networkStatus: networkStatus, | ||
loading: networkStatus === _networkStatus.NetworkStatus.loading | ||
}; | ||
}); | ||
}, | ||
setResult: function setResult(_ref) { | ||
@@ -71,3 +86,4 @@ var entries = _ref.entries, | ||
pageInfo: options.shouldSetPage ? page_info : state.pageInfo, | ||
loading: false | ||
loading: false, | ||
networkStatus: _networkStatus.NetworkStatus.ready | ||
}; | ||
@@ -74,0 +90,0 @@ }); |
@@ -88,2 +88,16 @@ "use strict"; | ||
var _networkStatus = require("./networkStatus"); | ||
Object.keys(_networkStatus).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
if (key in exports && exports[key] === _networkStatus[key]) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _networkStatus[key]; | ||
} | ||
}); | ||
}); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
@@ -90,0 +104,0 @@ |
@@ -10,2 +10,3 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; | ||
import createStore from "./store"; | ||
import { isRequestInFlight, NetworkStatus } from "../../networkStatus"; | ||
@@ -166,6 +167,20 @@ class Feed { | ||
var { | ||
setState | ||
setState, | ||
getState | ||
} = _this7.store; | ||
setState(store => store.setLoading(true)); // Always include the default params, if they have been set | ||
var { | ||
networkStatus | ||
} = getState(); // If there's an existing request in flight, then do nothing | ||
if (isRequestInFlight(networkStatus)) { | ||
return; | ||
} // Set the loading type based on the request type it is | ||
setState(store => { | ||
var _options$__loadingTyp; | ||
return store.setNetworkStatus((_options$__loadingTyp = options.__loadingType) !== null && _options$__loadingTyp !== void 0 ? _options$__loadingTyp : NetworkStatus.loading); | ||
}); // Always include the default params, if they have been set | ||
var queryParams = _objectSpread(_objectSpread({}, _this7.defaultOptions), options); | ||
@@ -180,3 +195,3 @@ | ||
if (result.statusCode === "error") { | ||
setState(store => store.setLoading(false)); | ||
setState(store => store.setNetworkStatus(NetworkStatus.error)); | ||
return { | ||
@@ -237,3 +252,4 @@ status: result.statusCode, | ||
_this8.fetch({ | ||
after: pageInfo.after | ||
after: pageInfo.after, | ||
__loadingType: NetworkStatus.fetchMore | ||
}); | ||
@@ -284,3 +300,5 @@ })(); | ||
metadata | ||
} = getState(); | ||
} = getState(); // Tnis is a hack to determine the direction of whether we're | ||
// adding or removing from the badge count | ||
var direction = type.startsWith("un") ? itemIds.length : -itemIds.length; | ||
@@ -287,0 +305,0 @@ setState(store => store.setMetadata(_objectSpread(_objectSpread({}, metadata), {}, { |
@@ -8,2 +8,3 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
import create from "zustand/vanilla"; | ||
import { NetworkStatus } from "../../networkStatus"; | ||
import { deduplicateItems, sortItems } from "./utils"; | ||
@@ -23,3 +24,6 @@ | ||
return create(set => ({ | ||
// Keeps track of all of the items loaded | ||
items: [], | ||
// The network status indicates what's happening with the request | ||
networkStatus: NetworkStatus.ready, | ||
loading: false, | ||
@@ -38,5 +42,11 @@ // Keeps track of the current badge counts | ||
}, | ||
// TODO: remove this function from the store as we're now using the | ||
// `setNetworkStatus` function to derive this information instead | ||
setLoading: loading => set(() => ({ | ||
loading | ||
})), | ||
setNetworkStatus: networkStatus => set(() => ({ | ||
networkStatus, | ||
loading: networkStatus === NetworkStatus.loading | ||
})), | ||
setResult: function setResult(_ref) { | ||
@@ -56,3 +66,4 @@ var { | ||
pageInfo: options.shouldSetPage ? page_info : state.pageInfo, | ||
loading: false | ||
loading: false, | ||
networkStatus: NetworkStatus.ready | ||
}; | ||
@@ -59,0 +70,0 @@ }); |
@@ -7,4 +7,5 @@ import Knock from "./knock"; | ||
export * from "./clients/preferences/interfaces"; | ||
export * from "./networkStatus"; | ||
export default Knock; | ||
export { Feed, FeedClient }; | ||
//# sourceMappingURL=index.js.map |
import { StoreApi } from "zustand"; | ||
import { FeedRealTimeEvent, FeedItemOrItems, FeedStoreState } from "./types"; | ||
import { FeedClientOptions } from "./interfaces"; | ||
import { FeedClientOptions, FetchFeedOptions } from "./interfaces"; | ||
import Knock from "../../knock"; | ||
@@ -27,3 +27,3 @@ export declare type Status = "seen" | "read" | "archived" | "unseen" | "unread" | "unarchived"; | ||
markAsUnarchived(itemOrItems: FeedItemOrItems): Promise<import("../../api").ApiResponse>; | ||
fetch(options?: FeedClientOptions): Promise<{ | ||
fetch(options?: FetchFeedOptions): Promise<{ | ||
status: "error"; | ||
@@ -38,3 +38,3 @@ data: any; | ||
status: "ok"; | ||
}>; | ||
} | undefined>; | ||
fetchNextPage(): Promise<void>; | ||
@@ -41,0 +41,0 @@ private broadcast; |
import { Activity, GenericData, User, PageInfo } from "../../interfaces"; | ||
import { NetworkStatus } from "../../networkStatus"; | ||
export interface FeedClientOptions { | ||
@@ -11,2 +12,5 @@ before?: string; | ||
} | ||
export declare type FetchFeedOptions = { | ||
__loadingType?: NetworkStatus.loading | NetworkStatus.fetchMore; | ||
} & FeedClientOptions; | ||
export interface ContentBlock { | ||
@@ -13,0 +17,0 @@ content: string; |
import { PageInfo } from "../../interfaces"; | ||
import { NetworkStatus } from "../../networkStatus"; | ||
import { FeedItem, FeedMetadata, FeedResponse } from "./interfaces"; | ||
@@ -12,5 +13,7 @@ export declare type StoreFeedResultOptions = { | ||
loading: boolean; | ||
networkStatus: NetworkStatus; | ||
setResult: (response: FeedResponse, opts?: StoreFeedResultOptions) => void; | ||
setMetadata: (metadata: FeedMetadata) => void; | ||
setLoading: (loading: boolean) => void; | ||
setNetworkStatus: (networkStatus: NetworkStatus) => void; | ||
setItemAttrs: (itemIds: string[], attrs: object) => void; | ||
@@ -17,0 +20,0 @@ }; |
@@ -7,4 +7,5 @@ import Knock from "./knock"; | ||
export * from "./clients/preferences/interfaces"; | ||
export * from "./networkStatus"; | ||
export default Knock; | ||
export { Feed, FeedClient }; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@knocklabs/client", | ||
"version": "0.4.4", | ||
"version": "0.4.5-rc.1", | ||
"description": "The clientside library for interacting with Knock", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/knocklabs/knock-client-js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
196812
81
2263