Code Monkey home page Code Monkey logo

frameworkeypromiseedition's Introduction

Frameworkey - Promise Edition

Frameworkey is an MVC framework designed around extensive use of Bluebird promises and controller-action composition

Have you ever felt that the callback model of Node can get kind of tiring? Have you ever wanted to elegantly chain controller actions "Unix-pipeline-style"? Have you ever wanted to use the return keyword in a web development setting? If you said yes to any of these questions, try out Frameworkey!

Frameworkey is written (primarily) using Literate Coffeescript, with a dash of JavaScript and regular CoffeeScript thrown in.

Installation

Before using Frameworkey, you must install CoffeeScript. From there, simply clone the repo and type npm install, and you're good to go!

Running

Run the following command in the console

NODE_ENV=<environment_variable> coffee app.litcoffee

Routing

Routing is the main reason Framework was built. Routes are defined in the config/routes.coffee file (you may convert it to regular JavaScript if you'd like). Routes are done in the format of

"METHOD /route" : "ControllerName.ActionName!ControllerName.errorHandler ControllerName.ActionName2 @ ControllerName.catchAllErrorHandler"

There are a few things to note here:

  • You may attach as many controller-actions to a route as you'd like.
  • You may handle errors individually by attaching a ! followed by the error-handler to the end of the method.
  • You may handle errors globally with a $ followed by the error handler to the end of the chain.
  • The results (either returned or promised) of the first function will be passed into the next function, and this will continue until the end of the chain.
  • You may break up your controllers with additional spaces or newlines if you'd like.

Note about API vs HTML Pages

There is an imposed standard for managing whether a page is an API-style web-service vs a server-rendered web page. If you'd like to make your page to be an API, make sure your last function returns an object with a renderType param with the choices of HTML or JSON (case insensitive), with the HTML type requiring a page parameter as well the name of the view you want to be run.

This might seem frustrating to some people, but generally I just write a couple functions like this:

makeAPI: (renderingItem) ->
	return {renderType: 'json', data: renderingItem}

makeDOM: (renderingItem) ->
      	return {renderType: 'html', data: renderingItem, page: 'testView'}

Due to the modular nature of the router, you only have to write these functions once, in one controller, and simply add them to the end of the route chain.

Policies

Policies aren't particularly hard to grasp, but are different than most frameworks out there.

Custom policies are defined in the /policies folder, and you may have as many as you'd like.

From there, policies can be attached to controllers and actions in the /config/policies.coffee file, which should be structured like so

	module.exports =
		someController:
			'someAction': ['yourDefinedPolicy']
			'*': 'catchAllPolicy'

Some notes about policies:

  • You may list several policies in an array. All the policies must return (or promise) true for the request to actually be satisfied. To decline permission, either reject the Promise, return false, or resolve false.
  • You may omit using an array if you only have one policy to attach to the action.
  • Anything that doesn't have a policy attached to it will fall back to whatever is attached to *.

While this is slightly different than tradition, it actually leads to a fairly pleasant programming experience. Don't knock it before you try it.

frameworkeypromiseedition's People

Contributors

bgammill avatar tombert avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

bgammill

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.