One Framework

1.4.6 · active · verified Sun Apr 19

One Framework, currently at version 1.4.6, is a structured web application framework built upon RxJS, Lodash, and React. It provides an opinionated architecture for managing application state through reactive `Model` and `Collection` classes, designed to seamlessly integrate with RESTful JSON APIs and, with future updates, WebSockets. Models and collections leverage RxJS observables (specifically Subjects), allowing any data changes to automatically propagate to subscribed React components, thereby keeping the view synchronized with the underlying state. The framework differentiates itself by tightly coupling these popular libraries into a cohesive, reactive data management layer, offering a clear pattern for data persistence, validation, and real-time updates within a client-side application. While the exact release cadence is not explicitly stated, the version number suggests active, ongoing development.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates creating a reactive `Model`, defining its schema and validation, subscribing to its `updateStream` for real-time changes, and modifying its properties.

import { Model } from 'one-framework';
import { Subject } from 'rxjs';

interface IUserAttributes {
  id?: string;
  name: string;
  email: string;
  isActive?: boolean;
}

class User extends Model<IUserAttributes> {
  resource = '/users';
  defaults = { isActive: true };
  idAttribute = 'id';

  validate(attributes: IUserAttributes) {
    if (!attributes.name) return { name: 'Name is required.' };
    if (!attributes.email || !attributes.email.includes('@')) return { email: 'Valid email is required.' };
    return {};
  }
}

const user = new User({ name: 'John Doe', email: 'john.doe@example.com' });

// Subscribe to changes on the model
user.updateStream.subscribe(change => {
  console.log('Model changed:', change.type, change.payload);
  console.log('Current user state:', user.toJSON());
});

console.log('Initial user:', user.toJSON());

// Set properties, triggering an update
user.set({ isActive: false });
user.set({ name: 'Jane Doe', id: 'uuid-123' });
user.unset('email');

// Attempt to save (requires a mock or actual backend)
// user.save().subscribe({
//   next: (response) => console.log('User saved:', response),
//   error: (err) => console.error('Save error:', err)
// });

view raw JSON →