Simple getter and OO in Javascript

Had a little drawback developing dia2statemachine because JS weird way of being poo Object Oriented.

Just so people know, there are setters and getters in DECENT BROWSERS , but of course IE doesn´t use them! They can significantly simplify the code, but what the helll, let´s keep it compatible at this time…

I was having lot´s of trouble to get a value out of a class in JS, turn´s out that, if there is a var a = true; inside a class I don´t have access to it from outside from calling, object.a -> (undefined), in the other hand, if it is declared inside the class as this.a = true , then I have access outside (set and get) but that is not O.O.

So a very simple way to make getters is>

snipp d2s

dev Dia -> ruby Statemachine part 1

Having so much fun right now! There´s been long before i had any fun on programming anything like I´m enjoying now 😀  the code is pretty nice so far!

Some Snippets:

To get the XML into HTML I built a really small ruby script that convert the file into a JS var and considering using the same script on the website to remove some of the ‘garbage’ out of the XML and print it on the page.

Dia->Statemachine: The tools

First of all, download DIA! =D

Select UML for the sheet pallet. Only a reduced set of the tools will be interpretated, the X´s will be ignored.

These is the selection of tools available:

dia - rubystatemachine

dia -> ruby statemachine

Ok! A quick note about the arrows, is that the 3 of those can be used under any TRANSITION circunstances (since all connect state with state), but you will see if you try, some arrows fit better in the indicated manner.

simple ex

simple ex

  • So that is a very basic example, it is valid, notice that you need to indicate a BEGINNING connected with a STATE since the XML has no defined order among the elements.
  • Not all TRANS are required to declare an action,  the EVENT alone is ok, but if your going to declare both  use  / to separate <  event_name / run_action >
  • On STATES you may use the fields: Entry action and Exit action they will trigger respectively on_enter, on_exit


Soon part 2

Converting Dia diagram to Ruby StateMachine =)

Hello !!!

After a loooong while I decided to dev something just so I don´t get too rusty!

The concept is: Statemachine is a fine implementation of FSM for ruby (act_as_state_machine is also an option). The author  wrote a nice guide for layperson (or forgetful like me :P) BUT still something is missing! In all examples there are diagrams, those are very necessary for us to understand what to implement in the machine, but a huge one´s mat get really confusing. The solution would be to convert the Diagram into Ruby code!

The plan: Dia is a great and easy to use diagramming tool, win and linux able, it´s save file is in XML.What i´m gonna do is make a JS that is able to parse it´s code and generate ruby =)

Execution:

  1. Make a definition of the simbols accepted by the conversion. Document it (blog).
  2. Understand the .dia XML, what is gonna be used inside?
  3. Make a website that receives a file .dia
  4. Make a response page with the contents
  5. In this page, JS will read, convert (the XML inside .dia) and return a ruby code for the statemachine in a textarea.
  6. In future (since the future is unknown this may never happen..) there will be no upload to the server, a Flash reads the content and return to JS.

Purpose: I love ruby lang, every Computer Science student must at least once use a Finite State Machine, maybe this interface will make things more attractive so he have a taste of ruby programming..

Long automata’s description may be very boring and error prone this should make the assembly easier.