Contributing Code
Development workflow
- Fork the repository on GitHub
git clone <https://github.com/YOUR_USERNAME/refract.git>
cd refract
- Create a feature branch from
main
git checkout -b feature/my-awesome-feature
- Make your changes with clear, focused commits
git add .
git commit -m "feat: add awesome new feature"
-
Add tests for new features
-
Update documentation if needed
-
Submit a pull request
git push origin feature/my-awesome-feature
Code style guidelines
Follow these consistent coding standards to keep code quality:
- ✅ Good - clear function names and documentation
/**
- Creates a new refraction with the given initial value
- @param {T} initialValue - The initial value for the refraction
- @returns {Refraction<T>} A new refraction instance
*/
export function createRefraction(initialValue) {
return new Refraction(initialValue);
}
- ✅ Good - consistent error handling
export function validateComponent(component) {
if (typeof component !== 'function') {
throw new RefractError(
'Component must be a function',
'INVALID_COMPONENT_TYPE'
);
}
}
- ✅ Good - clear variable names
const isComponentMounted = checkMountStatus(component);
const hasValidProps = validateProps(props);
- ❌ Avoid - unclear names and missing documentation
function cr(iv) {
return new R(iv);
}
const x = check(c);
Testing guidelines
All contributions should include appropriate tests, e.g:
Unit test example
describe("createRefraction", () => {
it("should create a refraction with initial value", () => {
const refraction = createRefraction(42);
expect(refraction.value).toBe(42);
});
it("should notify subscribers when value changes", () => {
const refraction = createRefraction(0);
const mockCallback = jest.fn();
refraction.subscribe(mockCallback);
refraction.set(10);
expect(mockCallback).toHaveBeenCalledWith(10);
});
it("should handle complex objects", () => {
const initialState = { count: 0, name: "test" };
const refraction = createRefraction(initialState);
expect(refraction.value).toEqual(initialState);
expect(refraction.value).not.toBe(initialState); // Should be immutable
});
});