MCPcopy Create free account
hub / github.com/caseywebdev/react-list / constrain

Function constrain

src/react-list.js:68–86  ·  view source on GitHub ↗
(props, state)

Source from the content-addressed store, hash-verified

66};
67
68const constrain = (props, state) => {
69 const { length, minSize, type } = props;
70 let { from, size, itemsPerRow } = state;
71 size = Math.max(size, minSize);
72 let mod = size % itemsPerRow;
73 if (mod) size += itemsPerRow - mod;
74 if (size > length) size = length;
75 from =
76 type === 'simple' || !from ? 0 : Math.max(Math.min(from, length - size), 0);
77
78 if ((mod = from % itemsPerRow)) {
79 from -= mod;
80 size += mod;
81 }
82
83 if (from === state.from && size === state.size) return state;
84
85 return { ...state, from, size };
86};
87
88export default class ReactList extends Component {
89 static displayName = 'ReactList';

Callers 4

constructorMethod · 0.70
updateVariableFrameMethod · 0.70
updateUniformFrameMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…