one
Version:
One is a React framework for web, iOS, and Android apps.
54 lines (51 loc) • 1.85 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var controlled_exports = {};
__export(controlled_exports, { useControlled: () => useControlled });
module.exports = __toCommonJS(controlled_exports);
var import_react = require("react");
function useControlled(onChange) {
var revision = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
if (!Number.isInteger(revision) || revision < 0 || revision > 2147483647) {
throw new Error("Control revision must be a nonnegative Int32");
}
var received = (0, import_react.useRef)({
eventCount: 0,
revision
});
var [acknowledged, setAcknowledged] = (0, import_react.useState)(received.current);
return {
revision,
acknowledgedEvent: acknowledged.revision === revision ? acknowledged.eventCount : 0,
onNativeChange(event) {
if (event.revision !== revision) return;
if (received.current.revision === revision && event.eventCount <= received.current.eventCount) return;
received.current = event;
try {
onChange(event);
} finally {
setAcknowledged(event);
}
}
};
}
//# sourceMappingURL=controlled.native.js.map