BlueRain OS
  • Introduction
  • API
    • API Reference
  • Guides
    • Apps
      • Installation
      • Creating an App
      • Configuration
    • Components
      • Registering Components
      • Extending Components
      • Replacing Components
      • Accessing Raw Components
      • Components & HoCs
    • Filters
      • Known Filters
    • Plugins
      • Installation
      • Configuration
      • Creating a Plugin
  • Miscellaneous
    • JSON to React
  • Plugins
    • Apollo
    • Internationalization
    • Material UI
    • React Router
    • Redux
    • Redux Devtools
    • Why Did You Update
Powered by GitBook
On this page
  • Adding Filter Functions
  • Removing Filter Functions
  • Running Filter Hooks
  1. Guides

Filters

BlueRain uses a system of filter hooks for many of its operations.

Adding Filter Functions

For example, here's how you would add a filter to posts.edit to give posts an editedAt date every time they are modified:

import BR from '@blueeast/bluerain-os';

BR.Filters.set('posts.edit', 'setEditedAt' , (post, user) => {
  post.editedAt = new Date();
  return post;
});

Removing Filter Functions

If the filter function is named (i.e. declared using the function foo () {} syntax), you can also remove it from the filter using:

import BR from '@blueeast/bluerain-os';

BR.Filters.remove('posts.edit', "setEditedAt");

Running Filter Hooks

Filters are run using the BR.Filters.run function:

modifier = BR.Filters.run(`movies.edit`, modifier, document, currentUser)

In each case, the first argument is the name of the filter hook, the second argument is the one iterated on by each filter function on the hook, while any remaining arguments are just passed along from one iteration to the next.

Note that each filter function should return the main argument to pass it on to the next function.

PreviousComponents & HoCsNextKnown Filters

Last updated 6 years ago