بنقرة واحدة
add-global
Create a reactive global variable that derives from atoms with subscription support
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Create a reactive global variable that derives from atoms with subscription support
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Create a new card part within a section with factory/class pattern, Card wrapper, and proper cleanup
Add a new Jotai atom to the state system with type definitions, registry, and Store API access
Create a reusable UI component with factory pattern, theme compatibility, and proper cleanup
Scaffold a new toggleable feature with full structure, storage, API exposure, and bootstrap registration
Create a game UI injection that modifies existing game elements with proper cleanup
Create a new core infrastructure module with standard API, lazy init, and proper structure
| name | add-global |
| description | Create a reactive global variable that derives from atoms with subscription support |
| aliases | ["new-global","create-global"] |
/add-global <globalName>
What derived state does this global provide?
Brief description:
Which atoms does this global derive from?
(List atom names from src/atoms/)
Examples: myInventoryAtom, myGardenAtom, weatherAtom
How is the global value computed from atoms?
A) Simple merge - Combine fields from multiple atoms
B) Transformation - Transform/filter atom data
C) Aggregation - Compute stats/totals from atoms
D) Complex - Multiple transformations
Should subscribers react to every atom change?
A) Yes - Every change triggers update
B) No - Only meaningful changes (use subscribeStable)
Expose in window.Gemini.Globals?
A) Yes
B) No - Internal only
src/globals/variables/<globalName>.tsimport { createReactiveGlobal } from '../core/reactive';
import { Store } from '../../atoms';
import type { GlobalVariable, Unsubscribe } from '../core/types';
// ─────────────────────────────────────────────────────────────────────────────
// Types
// ─────────────────────────────────────────────────────────────────────────────
export interface <GlobalName> {
// Derived fields
field1: string;
field2: number;
}
// ─────────────────────────────────────────────────────────────────────────────
// Derivation
// ─────────────────────────────────────────────────────────────────────────────
async function derive<GlobalName>(): Promise<<GlobalName>> {
const atom1 = await Store.select('sourceAtom1');
const atom2 = await Store.select('sourceAtom2');
return {
field1: atom1?.value ?? 'default',
field2: atom2?.count ?? 0,
};
}
// ─────────────────────────────────────────────────────────────────────────────
// Reactive Global
// ─────────────────────────────────────────────────────────────────────────────
const <globalName>Global = createReactiveGlobal<<GlobalName>>({
name: '<globalName>',
atomKeys: ['sourceAtom1', 'sourceAtom2'], // Atoms to watch
derive: derive<GlobalName>,
});
// ─────────────────────────────────────────────────────────────────────────────
// Public API
// ─────────────────────────────────────────────────────────────────────────────
let instance: GlobalVariable<<GlobalName>> | null = null;
export function get<GlobalName>(): GlobalVariable<<GlobalName>> {
if (!instance) {
instance = <globalName>Global;
}
return instance;
}
src/globals/index.tsexport { get<GlobalName> } from './variables/<globalName>';
export type { <GlobalName> } from './variables/<globalName>';
src/api/index.ts (if public)import { get<GlobalName> } from '../globals';
Globals: {
// ... existing
<globalName>: get<GlobalName>(),
}
src/globals/variables/<name>.tscreateReactiveGlobal() with correct atomKeysget() returns current valuesubscribe(callback) receives all updatessubscribeStable(callback) receives meaningful updates onlydestroy() is idempotentsrc/globals/index.tssrc/api/index.ts (if public)const global = get<GlobalName>();
// Get current value
const value = global.get();
// Subscribe to all changes
const unsub = global.subscribe((value) => {
console.log('Updated:', value);
});
// Cleanup
unsub();
const unsub = global.subscribeStable((value) => {
// Only fires on meaningful changes
updateUI(value);
});
const cleanups: (() => void)[] = [];
function start(): void {
const unsub = get<GlobalName>().subscribe((value) => {
onValueChange(value);
});
cleanups.push(unsub);
}
function stop(): void {
cleanups.forEach(fn => fn());
cleanups.length = 0;
}
.claude/rules/state/globals.mdsrc/globals/variables/src/globals/core/