Now.js

  • Home
  • Documentation
  • Components
  • Examples

Core API Reference

  1. Home
  2. Documentation
  3. API Reference
  4. Core API Reference

Framework Core

The Now.js framework core provides the foundation for building modern web applications. It handles

  • Framework initialization and configuration
  • Manager coordination
  • Resource loading
  • Error handling
  • Performance monitoring
  • Application lifecycle

Core Object

Properties

Now.version
Current framework version
Now.managers
Map of registered framework managers
Now.plugins
Map of registered plugins
Now.state
Framework internal state
Now.config
Framework configuration

Methods

Now.init(options)

Initialize the framework with options

await Now.init({ debug: true, environment: 'development', strictMode: true, security: { csrf: true, xss: true, csp: true } });
Now.createApp(config)

Create new application instance

const app = await Now.createApp({ name: 'My App', version: '1.0.0', plugins: [...], state: {...} });
Now.use(plugin, config)

Register plugin

Now.use(MyPlugin, { option1: 'value1', option2: 'value2' });
Now.registerManager(name, manager)

Register framework manager

Now.registerManager('customManager', CustomManager);
Now.getManager(name)

Get registered manager instance

const stateManager = Now.getManager('state');

Configuration

Core configuration options

{ // Core settings debug: false, environment: 'development', strictMode: true, // Security settings security: { csrf: true, xss: true, csp: true, validateInput: true, sanitizeOutput: true }, // Development tools devTools: { enabled: true, performance: true, logger: true, inspector: true }, // Performance settings performance: { monitoring: true, metrics: true, warnings: true, errorReporting: true }, // App defaults app: { name: 'Now.js Application', version: '1.0.0', description: '' } }

Error Handling

The framework provides comprehensive error handling

// Global error handler Now.handleError = function(error) { console.error('Framework Error:', error); // Use notification manager if available if (this.managers.has('notification')) { this.managers.get('notification').error( error.message || 'An error occurred' ); } // Use event manager if available if (this.managers.has('event')) { this.managers.get('event').emit('error', {error}); } };

Performance Monitoring

Built-in performance monitoring capabilities

// Start performance tracking Now.startPerformanceTracking('operation-name'); // End and record metrics Now.endPerformanceTracking('operation-name'); // Get performance metrics const metrics = Now.getPerformanceMetrics();

Resource Management

Framework resource loading and management

// Load resources await Now.loadResources([ 'css/styles.css', 'js/component.js' ], 'components'); // Check loaded resources const loaded = Now.state.loadedResources;

Development Tools

Development utilities available in debug mode

// Inspect framework state window.__NOW_DEV__.inspect(); // Get registered managers window.__NOW_DEV__.getManagers(); // Get loaded resources window.__NOW_DEV__.getResources(); // Get current configuration window.__NOW_DEV__.getConfig();

Application Lifecycle

Managing application lifecycle

// Create app const app = await Now.createApp(config); // Mount app to DOM await app.mount('#app'); // Clean up await Now.cleanup(); // Reset framework await Now.reset();

Events

Core framework events

  • framework:initialized - Framework initialization complete
  • app:created - New application instance created
  • app:mounted - Application mounted to DOM
  • error - Framework error occurred
  • performance:recorded - Performance metric recorded

Best Practices

  • Always initialize framework before creating applications
  • Use proper error handling
  • Enable development tools in development environment
  • Monitor performance metrics
  • Clean up resources when done

Browser Support

The framework core supports

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)
  • Other modern browsers that support ES6+

Related Documentation

  • Component API
  • Managers API
  • Plugin System

Now.js

Modern Frontend Framework

Documentation

  • Getting Started
  • Components
  • API Reference

Community

  • GitHub
  • Examples
  • Showcase

© 2024 Now.js. MIT License.