Skip to content
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

Allow for distinct JSONLogic instances #71

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

briandamaged
Copy link

This change exposes the JSONLogic factory function so that multiple independent instances of JSONLogic can be instantiated at once. For example:

// The module itself still acts like a JSONLogic instance.
const defaultInstance = require('json-logic-js');
defaultInstance.apply({"<": [2, 3]});

// However, now you can create additional instances of
// JSONLogic as well.  Each instance can have its own
// custom operators.
const myInstance = new defaultInstance.JSONLogic();

myInstance.add_operation("join", function(ary, glue) {
  return ary.join(glue);
});

myInstance.apply({"join": [ ["foo", "bar"], ","] });

@briandamaged
Copy link
Author

Alright -- here's the re-implementation of #70 . This does the same thing, but it eliminates the re-indentation.

@briandamaged
Copy link
Author

@jwadhams : ping

@josephdpurcell
Copy link

I like this idea! I'm a bit new to JSON Logic, but in the back of my mind I was thinking about how when you add operations it would be added globally. On principle, it would be nice to have the ability to have multiple instances of JSON Logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants