frame-js / Frame

Frame is a flow based programming library for databases, APIs, utilities, objects, schemas and more!
MIT License
17 stars 2 forks source link
api bootstrap chainable databases declarative flow flow-based-programming flow-control frame javascript library microcosm monad object orm schema turn-based utilities

This project has moved to FlowJS

Why the move?

The code has been dranatically simplified and easier to reason about. Rather than trying to solve too many problems (like dynamic imports), it leaves these to your builder or toolchain of choice (New ES6 Imports can do this for you).

Instead, we now focus solely on Code Flow Control.


Frame

Frame is a flow based programming library for databases, APIs, utilities, objects, schemas and more!

Features:


Coming Soon:


Pseudo-Examples:

Custom Loaders

// From Github files
const SomeBlueprint = Frame("git://pathToYourFile.js")

// From Github repos
const SomeBlueprintFromRepo = Frame("git://SomeOrganization/YourFavoriteRepo")

// From HTTP URLs
const BlueprintFromURL = Frame("http://example.com/yourFile.js")

// From many different databases and stores
const BlueprintFromDB = Frame("mongodb://fileInDb.js")

Easy syntax

Render HTML/CSS with a Message from a database (Gun)

Message
  .from(Gun) // Receive a message from a database
  .to(Schema) // Validate message format
  .to(HTML) // Convert to HTML
  .to(Style) // Dynamic styles!
  .to(RenderFunction) // Finally render it, using our own function

Order does not matter

// Example #1: Multiple event handlers (Left to right processing.)
Message
  .from(Slack)
  .from(Gitter)
  .to(Console)

// Example #2: (Right to left processing.)
Message
  .to(Console)
  .from(Slack)
  .from(Gitter)

Example #3: (Somewhere in the middle)
Message
  .from(Slack)
  .to(Console)
  .from(Gitter)


Using setters to chain to/from:

// Can be a function
Message.from = function(data, props, cb) {}

// Can be an arrow function
Message.from = (data, _, cb) => cb()

// Can be a Blueprint module
Message.from = Slack

// Can be a primitive value
Message.from = 'Something'


Blueprint.js Example:

Blueprint = {
  name: 'Console',

  in: function(data) {
    return console.log(data)
  },
}

Functional Programming:

function registerGunMessage() {
    gun.get(“app”).get(“users”).on(this.out)
}

Gun.from(registerGunMessage).to(Console)

Multiple flow paths (Coming soon):

Message.from(Gun).to(Schema).or.to(Error)

Fallback support for API, Databases, etc:

Message
  .from(Socket)
  .to(DB1)
  .or() // call it like a function
  .to(DB2)
  .or // can also be used with dot notation
  .to(DB3)
  .or
  .to(Sentry)
  .timeout(5000) // Timeouts for any of the Blueprints!

Property Descriptions for automatic destructuring:

Blueprint = {
  describe: {
    in: {
      firstPropName: 'Some property desscription.',
      secPropName: 'Some other prop description.',
    }
  }

  in: function(data, props) {
    // props.firstPropName
    // props.secPropName
  }
}

Multiple return styles:

Blueprint = {
  // Callback style - follows (err, data) callback convention
  in: function(data, props, callback) {
    callback(null, 'some data')
  },

  // return primitives
  in: function(data, props) {
    return 'some data'
  },

  // return promises
  in: function(data) {
    return new Promise(function(resolve, reject) {
      resolve('some data')
    })
  },

  // async/await
  in: async function(data) {
    return await someAsyncFunction()
  },

  // Out event
  in: function(data) {
    this.out('some data')
  },
}

More Examples coming soon!