VARUNA JAYASIRI

@vpj

Another JS Framework

December 17, 2013

I started working on Sweet.js about a month ago. It is inspired by Backbone.js. Sweet.js supports HTML5 states, so that you don't have to go through work arounds like these. Sweet.js is not a MVC framework, but it has a views similar to Backbone.js, which supports inheritance without affecting events and initializations of super classes. And it's written in Coffeescript.

Router

class Router extends Sweet.Router
 @routes #You can add more routes from sub classes
  '': 'home'
  'search/:what': 'results'

 home: ->
  View.home()

 results: (what) ->
  console.log @getState() #state
  View.results(what)

router = new Router()
router.start pushState: true

#Emulate browser back button
router.back()

#Whether we can go back without leaving the web app
router.canBack()

Views

A generic form class.

class Form extends Sweet.View
 @events
  'click .cancel': 'cancel'
  'click .submit': 'submit'

 @initialize (options) ->
  @model = options.model

cancel: (e) ->
 router.back()

A registration form class.

class RegistrationForm extends Sweet.View
 #Register new events without affecting events registered in Form class
 @events
  'click .checkUsername': checkUsername

 #Both initialization functions (Form, RegistrationForm) will be called.
 @initialize (options) ->
  @userType = options.userType

 submit: (e) ->
  #Submit form

 checkUsername: (e) ->
  #Check availability

This is a very basic library and it will not suit you if you are looking for a MVC. I'm using this in some of my projects, so I will be maintaining it.

I'm planning to remove the dependency on jQuery and use vanilla javascript.

///Another JS Framework ///2013-12-17 I started working on **<<https://github.com/vpj/sweet(Sweet.js)>>** about a month ago. It is inspired by <<http://backbonejs.org/(Backbone.js)>>. Sweet.js supports HTML5 states, so that you don't have to go through work arounds like <<https://news.ycombinator.com/item?id=6872330(these)>>. Sweet.js is not a MVC framework, but it has a views similar to Backbone.js, which supports inheritance without affecting events and initializations of super classes. And it's written in Coffeescript. >>> **<<https://news.ycombinator.com/item?id=6920522(Discuss on Hacker News)>> ## Router ```coffeescript class Router extends Sweet.Router @routes #You can add more routes from sub classes '': 'home' 'search/:what': 'results' home: -> View.home() results: (what) -> console.log @getState() #state View.results(what) router = new Router() router.start pushState: true #Emulate browser back button router.back() #Whether we can go back without leaving the web app router.canBack() ## Views A generic form class. ```coffeescript class Form extends Sweet.View @events 'click .cancel': 'cancel' 'click .submit': 'submit' @initialize (options) -> @model = options.model cancel: (e) -> router.back() A registration form class. ```coffeescript class RegistrationForm extends Sweet.View #Register new events without affecting events registered in Form class @events 'click .checkUsername': checkUsername #Both initialization functions (Form, RegistrationForm) will be called. @initialize (options) -> @userType = options.userType submit: (e) -> #Submit form checkUsername: (e) -> #Check availability This is a very basic library and it will not suit you if you are looking for a MVC. I'm using this in some of my projects, so I will be maintaining it. I'm planning to remove the dependency on jQuery and use vanilla javascript.