Code Monkey home page Code Monkey logo

sproutcore-statechart's Introduction

SproutCore (Ember.js) Statechart

Description:

This is a port of the SproutCore Statechart library from the SproutCore 1.x framework for use in SproutCore 2.0 (Ember.js) applications. It was principally authored by Michael Cohen (aka. FrozenCanuck).

Synopsis:

TODO: Add documentation to the README.

For the time being, there are plenty of examples in the source code, and example usage throughout the extensive unit tests.

Learning by Example

We are working hard to provide more documentation and examples for Ember.js and here specifically for the statechart framework. Until there is more, you can learn from this example:

Quick Notes - Example Ember.js Application for statecharts and routing support

Building sproutcore-statechart.js

You need ruby and some gems to build the source code and to run unit tests.

  1. Install Ruby 1.9.2+. There are many resources on the web can help; one of the best is rvm.

  2. Install Bundler: gem install bundler

  3. Run bundle inside the project root to install the gem dependencies.

  4. Run rake to build sproutcore-statechart.js. Two builds will be placed in the dist/ directory.

  5. sproutcore-statechart.js and sproutcore-statechart.min.js - unminified and minified builds of sproutcore-statechart.js

If you are building under Linux, you will need a JavaScript runtime for minification. You can either install nodejs or gem install therubyracer.

Running / Writing Unit Tests:

The repository has been refactored to use the same structure as the Ember.js project:

  1. To start the development server, run bundle exec rackup.

  2. Then visit: http://localhost:9292/tests/index.html?package=all

You can also pass jquery=VERSION in the test URL to test different versions of jQuery. Default is 1.7.1.

Features / Problems:

  • The stateObserves() helper does not properly work with global paths. These problems are captured in the unit tests
  • There are a few fixes for bugs that are in the SproutCore 1.x version that have not been ported over as of yet.
  • The Unit Tests for route triggered are failing at the moment, but it works -> needs to be fixed!

If you run into a problem, please file an issue on this repository.

Requirements:

In order to use the Statechart package, you'll need two libraries:

These dependencies are automatically installed if you're using BPM. If you want to download and use the JS file (and assuming you're already using SproutCore 2.0), don't forget to grab the built version of the Utils package.

You can also simply include a built version of Ember.js before ember-statechart.js

Install:

You can use the Statechart package by either downloading the JavaScript files provided in the Downloads section of this repository or using BPM. To install it via BPM, simply run

bpm add sproutcore-statechart

And this will handle adding all of its dependencies as well. You, of course, need to be using BPM for your application or package for this to work ;)

sproutcore-statechart's People

Contributors

benjixx avatar colincampbell avatar ebryn avatar krisselden avatar lukemelia avatar mlcohen avatar oruen avatar pklingem avatar stevenh512 avatar tbartelmess avatar wycats avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sproutcore-statechart's Issues

"SC is undefined"

I am using bpm to install sproutcore-statechart.

It installed the dependencies successfully but when I opened the index.html it says: "SC is undefined".

Could this be fixed?

broken build

I'm seeing a couple of issues when trying to build the sproutcore-statechart framework.

The first is that the self-executing anonymous functions that get wrapped around each file's contents do not have a trailing semicolon. When you have two of these back to back, its interpreted as chained function calls and triggers an exception.

(function() {})()
(function() {})()
// => TypeError: function () {}() is not a function

This issue can be fixed by removing the following lines of code from the Rakefile:

module SproutCore
  module Compiler
    class Entry
      def body
        "\n(function(exports) {\n#{@raw_body}\n})({})\n"
      end 
    end 
  end 
end

The second and larger issue is that the files are getting built out of order. SC.EmptyState is getting defined before SC.State, which is a problem because SC.EmptyState extends SC.State. The dependencies in lib/system.js are not listed in the correct order, but fixing the order does not seem to affect the build.

require('sproutcore-statechart') doesn't work

UPDATED 20 Sep!!
.........................................................................................................
I can't get statecharts using bpm working. I get the following error.

syntax error
[Break On This Error] __evalFunc = function(a,b,c,d,e,f){var...efined)};return c.statePlugin=YES,c}}
in file:///.../my_app/assets/bpm_libs.js
Line 6

I am using:
spade (1.0.1)
sproutcore-metal (2.0.beta.3)
sproutcore-runtime (2.0.beta.3)
jquery (1.6.2)
sproutcore-views (2.0.beta.3)
handlebars (1.0.0.beta.3)
sproutcore-handlebars-format (2.0.beta.3.1)
sproutcore-handlebars (2.0.beta.3)
sproutcore (2.0.beta.3.1)
sproutcore-utils (2.0.beta.3)
sproutcore-statechart (2.0.beta.3)

Steps to reproduce error:

  1. bpm init my_app && cd my_app
  2. bpm add sproutcore --pre
  3. bpm add spade
  4. bpm add sproutcore-statechart -v 2.0.beta.3 --pre
  5. adding the following in index.html
    spade.require('my_app');
  6. Add following code in lib/main.js
    //main.js
    require('sproutcore');
    require('sproutcore-statechart');
    MyApp = SC.Application.create();

When I then start bpm preview and go to localhost:4020/index.html in the browser I encounter the error. If I comment out require('sproutcore-statechart') it works just fine.

sendAction() calls the passed function more then necessary when sent from concurrent substates' enterState()

The number of times the action is called is multiplied by order the substate was defined.

Demonstration: http://shellshaper.com/sproutcore/sendaction-bug/

Code:

var App = SC.Application.create();

App.statechart = SC.Object.extend(SC.StatechartManager, {
  rootState: SC.State.extend({

    substatesAreConcurrent: true,

    testAction: function(sender) {
      var output = "testAction sent from: "+sender;
      $('body').append('<div>'+output+'</div>');
      console.log(output);
    },

    stateA: SC.State.extend({
      enterState: function() {
        this.statechart.sendAction('testAction', this.get('stateName'));
      }
    }),
    stateB: SC.State.extend({
      enterState: function() {
        this.statechart.sendAction('testAction', this.get('stateName'));
      }
    }),
    stateC: SC.State.extend({
      enterState: function() {
        this.statechart.sendAction('testAction', this.get('stateName'));
      }
    })
  })
});

App.statechart = App.statechart.create();

Output:

testAction sent from: stateA
testAction sent from: stateB
testAction sent from: stateB
testAction sent from: stateC
testAction sent from: stateC
testAction sent from: stateC

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.