Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
reactive-box
Advanced tools
Minimal reactive box
import React from "react";
import { box, sel, expr } from "reactive-box";
interface Todo {
text: string;
completed: boolean;
}
const [getTodos, setTodos] = box<Todo[]>([]);
const [countActive] = sel(
() => getTodos().filter((todo) => !todo.completed).length
);
const [countCompleted] = sel(
() => getTodos().filter((todo) => todo.completed).length
);
const addTodo = (text: string) => {
setTodos([...getTodos(), { text, completed: false }]);
};
const switchTodo = (target: Todo) => {
setTodos(
getTodos().map((todo) =>
target === todo
? {
...todo,
completed: !todo.completed
}
: todo
)
);
};
const clearCompleted = () => {
setTodos(getTodos().filter((todo) => !todo.completed));
};
const observe = <T extends React.FC>(Component: T) =>
React.memo((props) => {
const update = React.useState(0)[1];
const ref = React.useRef<[T, () => void]>();
if (!ref.current) {
const [Observed, free] = expr(Component, () =>
update((v) => (v + 1) % 0xffff)
);
ref.current = [Observed, free];
}
React.useEffect(() => ref.current![1], []);
return ref.current[0](props);
});
const TodoInput = observe(() => {
const [getText, changeHandler, clickHandler] = React.useMemo(() => {
const [getText, setText] = box("");
return [
getText,
(ev: React.ChangeEvent<HTMLInputElement>) => setText(ev.target.value),
() => {
addTodo(getText());
setText("");
}
];
}, []);
return (
<div>
Todo: <input value={getText()} onChange={changeHandler} />
<button onClick={clickHandler}>+</button>
</div>
);
});
const TodoList = observe(() => (
<ul>
{getTodos().map((todo, key) => (
<li key={key}>
{todo.text}{" "}
<button onClick={() => switchTodo(todo)}>
{todo.completed ? "open" : "close"}
</button>
</li>
))}
</ul>
));
const TodoFooter = observe(() => {
const active = countActive();
const completed = countCompleted();
return (
<div>
{active ? `${active} left ` : null}
{completed ? (
<button onClick={clearCompleted}>clear completed</button>
) : null}
</div>
);
});
export default function App() {
return (
<>
<TodoInput />
<TodoList />
<TodoFooter />
</>
);
}
npm i reactive-box
Enjoy!
FAQs
Minimalistic, fast, and highly efficient reactivity
The npm package reactive-box receives a total of 82 weekly downloads. As such, reactive-box popularity was classified as not popular.
We found that reactive-box demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.