Skip to content

Added getting started with instance mode file in mdx #758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/content/tutorials/en/getting-started-with-instance-mode.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: Getting Started with p5.js Instance Mode
description: Learn how to set up and use p5.js in instance mode for better modularity and compatibility.
category: drawing
---

# Getting Started with Instance Mode

## What is Instance Mode?

Instance mode allows you to create multiple independent instances of the library, rather than relying on a single global instance. This approach provides better encapsulation, flexibility, and avoids conflicts in complex applications.

## Why Use Instance Mode?

Instance mode is preferred in scenarios where multiple independent configurations are needed within the same application. Unlike global mode, which shares state across all components, instance mode ensures better isolation and control.

## Advantages of Instance Mode

- **Encapsulation**: Each instance maintains its own state, avoiding unintended side effects.
- **Flexibility**: Different configurations can be applied to different instances.
- **Scalability**: Easier to manage in large applications with multiple independent modules.
- **Avoids Conflicts**: Prevents state pollution from shared global variables.
- **Better Testability**: Each instance can be tested independently.

## Limitations of Instance Mode

- **Increased Memory Usage**: Multiple instances consume more resources compared to a single global instance.
- **More Setup Required**: Requires explicit initialization for each instance.
- **Potential Redundancy**: If all instances share the same configuration, a global instance might be more efficient.

## When to Choose Instance Mode Over Global Mode?

- **When working with multiple independent modules** that require different configurations.
- **When developing modular applications**, ensuring isolated behavior.
- **When avoiding global state conflicts** is necessary.
- **When testing individual components**, making unit testing easier.

By choosing instance mode in the right scenarios, you can achieve better modularity and maintainability in your project.