Reading Settings

Learn how to access and use settings values in your expansions.


App Settings

App settings are stored in localStorage and accessible globally.

Method 1: Using API

Recommended method - Simple and consistent.

const settings = api.nexomaker.getAppSettings();
const apiKey = settings['api-key'] || '';
const enabled = settings['enable-feature'] || false;

Method 2: Direct localStorage

Direct access to localStorage for advanced use cases.

const settingsJson = localStorage.getItem('app-settings');
const settings = JSON.parse(settingsJson || '{}');
const apiKey = settings['api-key'] || '';

Method 3: Event Listener

Listen for real-time changes to react immediately.

window.addEventListener('app-settings-changed', (event) => {
  const { settings } = event.detail;
  console.log('Settings updated:', settings);
  
  // React to specific changes
  if (settings['enable-auto-sync']) {
    startAutoSync(settings['sync-interval']);
  } else {
    stopAutoSync();
  }
});

Project Settings

Project settings are stored in YAML files and specific to each project.

Reading from YAML

Reading from Different YAML Keys


Best Practices

1. Always Provide Fallback Values

Settings might not exist yet, so always provide defaults.

2. Use Consistent Key Names

Keep key naming consistent between registration and reading.

3. Handle Async Operations

Project settings are async, so use async/await or promises.

4. Cache Settings When Appropriate

Avoid reading settings repeatedly in loops.

5. Listen for Changes

React to settings changes in real-time.


Common Patterns

Initialize on Load

Project-Specific Logic

Combining App and Project Settings

Conditional Feature Activation


Examples

Simple App Settings

Project Settings with Validation


Troubleshooting

Settings Return Undefined

Problem: Reading settings returns undefined.

Solutions:

  1. Check that settings tab is registered first

  2. Verify key names match exactly

  3. Provide fallback values: settings['key'] || 'default'

Changes Don't Reflect

Problem: Updated settings don't show.

Solutions:

  1. For app settings: Check if using event listener

  2. For project settings: Re-read YAML after changes

  3. Clear cache if caching settings

Async Issues

Problem: Project settings return promises.

Solutions:

  1. Use async/await

  2. Add .then() handlers

  3. Don't use project settings in synchronous code


Next Steps

  • Learn about best practices →

  • See complete examples →

  • Create custom elements →

Last updated