one
Version:
One is a React framework for web, iOS, and Android apps.
1 lines • 1.49 kB
Source Map (JSON)
{"version":3,"file":"controlled.js","names":[],"sources":["esm/platform/controlled.js"],"sourcesContent":["import { useRef, useState } from \"react\";\nfunction useControlled(onChange, revision = 0) {\n if (!Number.isInteger(revision) || revision < 0 || revision > 2147483647) {\n throw new Error(\"Control revision must be a nonnegative Int32\");\n }\n const received = useRef({ eventCount: 0, revision });\n const [acknowledged, setAcknowledged] = useState(received.current);\n return {\n revision,\n acknowledgedEvent: acknowledged.revision === revision ? acknowledged.eventCount : 0,\n onNativeChange(event) {\n if (event.revision !== revision) return;\n if (received.current.revision === revision && event.eventCount <= received.current.eventCount)\n return;\n received.current = event;\n try {\n onChange(event);\n } finally {\n setAcknowledged(event);\n }\n }\n };\n}\nexport {\n useControlled\n};\n//# sourceMappingURL=controlled.js.map\n"],"mappings":";;;AACA,SAAS,cAAc,UAAU,WAAW,GAAG;CAC7C,IAAI,CAAC,OAAO,UAAU,QAAQ,KAAK,WAAW,KAAK,WAAW,YAAY;EACxE,MAAM,IAAI,MAAM,8CAA8C;CAChE;CACA,MAAM,WAAW,OAAO;EAAE,YAAY;EAAG;CAAS,CAAC;CACnD,MAAM,CAAC,cAAc,mBAAmB,SAAS,SAAS,OAAO;CACjE,OAAO;EACL;EACA,mBAAmB,aAAa,aAAa,WAAW,aAAa,aAAa;EAClF,eAAe,OAAO;GACpB,IAAI,MAAM,aAAa,UAAU;GACjC,IAAI,SAAS,QAAQ,aAAa,YAAY,MAAM,cAAc,SAAS,QAAQ,YACjF;GACF,SAAS,UAAU;GACnB,IAAI;IACF,SAAS,KAAK;GAChB,UAAU;IACR,gBAAgB,KAAK;GACvB;EACF;CACF;AACF"}