# Migrating from V3

BlueRain V4 is a complete rewrite of the whole framework. These have resulted in some major breaking changes. We made a conscious decision to go ahead with it since we a major version, we wanted to do what's right, rather than carry mistakes of previous version.

This page should serve as a guide to migrate BlueRain projects from V3.

## New Version, New Name

The project name has changed in V4. Previous the framework was called `BlueRain OS`. We have decided to drop the `OS` part. So now, it's just `BlueRain`.

![We're calling it... BlueRain](https://578577164-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LLIgFpAH192hlMWkll_%2F-LO2FhPELFb0cfhasaTJ%2F-LO2G1mZemdg5jvAFE1F%2Ftoy-story.png?alt=media\&token=af56691b-5a14-4c65-b75b-1e1b7ce4403d)

From V4 onwards, the project will move to it's new homes at:

* [Github](https://github.com/BlueEastCode/bluerain)
* [NPM](https://www.npmjs.com/package/@blueeast/bluerain)

Unfortunately, this also means that all import statements need to be migrated as well.&#x20;

```diff
- import { BlueRain } from '@blueeast/bluerain-os';
+ import { BlueRain } from '@blueeast/bluerain';
```

## Bye Bye, withBlueRain

Theres no easy way to say this but... `withBlueRain` HOC is gone! Use `BlueRainConsumer` component instead.

We did this to simplify the API and to keep the bundle size in check.&#x20;

```diff
- const Button = withBlueRain(({ BR, ...rest }) => {
-     return <BR.Components.Button {...rest} />;
- });

+ const Button = (props) => (
+     <BlueRainConsumer>
+     {(BR) => <BR.Components.Button {...props} />}
+     </BlueRainConsumer>
+ );
```

## No Singleton Instance

In V3 we used a single instance of BlueRain. This instance was exported from the library as `default` and `BR`. This has been removed in the V4. This means:

* Now there is not default export in BlueRain 4.
* Now there is no single BlueRain instance exported.

This also allows us to use more than one BlueRain apps in a single project.

## Hooks

### Registry methods

Since registry codebase has been completely revamped, the internal API and methods has  changed. So, if you use any of the `BR.Hooks` class methods directly, be sure to check docs for changes.&#x20;

Some important changes are listed below:

#### Add/Remove methods

`add` and `remove` methods have been renamed to `register` and `unregister` respectively.

#### Set method

Behavior of set and remove has changed.&#x20;

* `set` method sets the whole array of all listeners of a hook, as opposed to a single listener.

### Filter and Event Registries

Hooks in V3 were made of 2 registries:

* FilterRegistry
* EventRegistry

Both of these have been removed, and we only have a single unified registry now, i.e. HookRegistry.

This also means that there are no `BR.Filters` and `BR.Events` properties in BlueRain context anymore.

### Running a Hook

#### Return Type

All `BR.Hooks.run` now returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that resolves a value, previously it just returned the value.

```diff
- modifier = BR.Hooks.run('movies.edit', modifier);
+ modifier = await BR.Hooks.run('movies.edit', modifier);
```

#### Arguments in handler function

In V3 a hook handler function could receive any number of arguments. This has been changed and now a hook can only receive 3 fixed arguments.

```diff
- BR.Hooks.run('movies.edit', movie, actors, collections);
+ BR.Hooks.run('movies.edit', movie, { actors, collections });
```

More details of about the arguments passed to the [handler function](https://blueeast.gitbook.io/bluerain/key-concepts/hooks#handler-function) can be found here.

## Plugins

### Registry methods

Since registry codebase has been completely revamped, the internal API and methods has  changed. So, if you use any of the `BR.Plugins` class methods directly, be sure to check docs for changes.&#x20;

Some important changes are listed below:

#### Add/Remove methods

`add` and `remove` methods have been renamed to `register` and `unregister` respectively.

#### Set method

Behavior of set and remove has changed.&#x20;

* `set` method sets the whole array of all listeners of a hook, as opposed to a single listener.

#### initializeAll method

`initializeAll` method has been removed. Use `bluerain.plugins.initialize.all` hook instead.

```diff
- BR.Plugins.initializeAll();
+ await BR.Hooks.run('bluerain.plugins.initialize.all', bootOptions);
```

#### registerMany method

`registerMany` method has been removed. Use `bluerain.plugins.register` hook instead.

```diff
- BR.Plugins.registerMany(plugins);
+ await BR.Hooks.run('bluerain.plugins.register', bootOptions);
```

## Components

### IconEnhanced

IconEnhanced Component has been renamed to `DynamicIcon`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blueeast.gitbook.io/bluerain/guides/migrating-from-v3.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
