Work with arrays efficiently! Push, filter, map - all optimized for reactive programming.
createArraySignal()Add items, filter, sort - all changes are reactive!
import { createArraySignal } from 'signalforge/utils';
// Create reactive array
const todos = createArraySignal([
{ id: 1, text: 'Learn SignalForge', done: false },
{ id: 2, text: 'Build amazing app', done: false }
]);
// Subscribe to changes
todos.subscribe(() => {
console.log('Todos updated:', todos.get());
});
// Add items
todos.push({ id: 3, text: 'Deploy to production', done: false });
// Triggers subscriber!
// Remove items
todos.remove(todos.find(t => t.id === 2));
// Triggers subscriber!
// Filter items
todos.filter(t => !t.done);
// Triggers subscriber!
// Map (read-only, doesn't trigger)
const texts = todos.map(t => t.text);
// Use in React
function TodoList() {
const [items, setItems] = useState([]);
useEffect(() => {
const updateItems = () => setItems([...todos.get()]);
updateItems();
return todos.subscribe(updateItems);
}, []);
return (
<ul>
{items.map(todo => (
<li key={todo.id}>{todo.text}</li>
))}
</ul>
);
}const todos = createArraySignal([]);
todos.push(newTodo);
todos.remove(completedTodo);const cart = createArraySignal([]);
cart.push(product);
const total = cart.map(i => i.price);const messages = createArraySignal([]);
messages.push(newMessage);
messages.filter(m => !m.deleted);const rows = createArraySignal([]);
rows.sort((a, b) => a.name - b.name);
rows.filter(r => r.active);Perfect for todos, cart items, messages, table rows, etc.
Methods like push, filter, sort are optimized to only update what changed.
If you know JavaScript arrays, you already know how to use array signals!
Every mutation triggers subscribers - no manual notify() calls needed.