MCPcopy Create free account
hub / github.com/WebReflection/neverland / useReducer

Function useReducer

index.js:353–386  ·  view source on GitHub ↗
(reducer, value, init, options)

Source from the content-addressed store, hash-verified

351 };
352
353 var useReducer = function useReducer(reducer, value, init, options) {
354 var i = state.i++;
355 var _state = state,
356 hook = _state.hook,
357 args = _state.args,
358 stack = _state.stack,
359 length = _state.length;
360 if (i === length) state.length = stack.push({});
361 var ref = stack[i];
362 ref.args = args;
363
364 if (i === length) {
365 var fn = typeof init === 'function';
366
367 var _ref = (fn ? options : init) || options || defaults,
368 asy = _ref.async,
369 always = _ref.always;
370
371 ref.$ = fn ? init(value) : getValue(void 0, value);
372 ref._ = asy ? updates.get(hook) || updates.set(hook, reraf()) : hookdate;
373
374 ref.f = function (value) {
375 var $value = reducer(ref.$, value);
376
377 if (always || ref.$ !== $value) {
378 ref.$ = $value;
379
380 ref._(hook, null, ref.args);
381 }
382 };
383 }
384
385 return [ref.$, ref.f];
386 }; // useState
387
388 var useState = function useState(value, options) {
389 return useReducer(getValue, value, void 0, options);

Callers 1

useStateFunction · 0.70

Calls 3

getValueFunction · 0.85
reducerFunction · 0.85
rerafFunction · 0.70

Tested by

no test coverage detected