Skip to content
This repository has been archived by the owner on Jan 6, 2021. It is now read-only.

Commit

Permalink
API cleanup, Gremlin inheritance for coffee and js
Browse files Browse the repository at this point in the history
  • Loading branch information
grmlin committed Nov 10, 2013
1 parent f577ba9 commit 67be65c
Show file tree
Hide file tree
Showing 16 changed files with 207 additions and 94 deletions.
2 changes: 1 addition & 1 deletion dist/gremlin.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "GremlinJS",
"version": "0.5.1",
"version": "0.6.0",
"main": "./src/scripts/GremlinJS.coffee",
"license": "MIT",
"repository": {
Expand Down
14 changes: 14 additions & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Release notes

## v0.6.0 *2013-11-10*

### New

- `G.Gizmo.extend` to inherit from gremlin classes
- `G.Package.require` to reference packages

### Removed

- `G.define`, use `G.Gizmo.extend`
- `G.require`, use `G.Package.require`
- `G.namespace`, `G.ns`, use `G.Package.require`
- `G.Gizmo#klass`, use `G.Gizmo#constructor`

## v0.5.1 *2013-11-6*

### New
Expand Down
12 changes: 1 addition & 11 deletions src/scripts/Gremlin.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ goog.require 'EventDispatcher'
goog.require 'conf.Configuration'
goog.require 'util.Helper'
goog.require 'util.Debug'
goog.require 'namespace'
goog.require 'packages.Package'
goog.require 'modules.Module'
goog.require 'Application'
Expand All @@ -31,20 +30,11 @@ Gremlin = do ->
app?.refresh()
GremlinClass

define: (name, constructor, instanceMembers, staticMembers) ->
GremlinClass = gremlinDefinitions.Pool.getInstance().define name, constructor, instanceMembers, staticMembers
app?.refresh()
GremlinClass

#derive: (parentName, name, constructor, instanceMembers, staticMembers) ->

Gizmo: gremlinDefinitions.Gizmo

Helper: util.Helper
Module: modules.Module
namespace: namespace
ns: namespace
Package: packages.Package
require: packages.Package.get

g = new GremlinAdapter

Expand Down
30 changes: 28 additions & 2 deletions src/scripts/gremlinDefinitions/Gizmo.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
goog.provide 'gremlinDefinitions.Gizmo'

goog.require 'util.Helper'

class gremlinDefinitions.Gizmo

define = (Parent, constructor, instanceMembers, staticMembers) ->
unless typeof constructor is 'function'
throw new Error("The second parameter when defining a gremlin has to be the constructor function!")

unless typeof instanceMembers is 'undefined' or typeof instanceMembers is 'object'
throw new Error("The third parameter when defining a gremlin has to be an object providing the instance members of the gremlin!")

unless typeof staticMembers is 'undefined' or typeof staticMembers is 'object'
throw new Error("The fourth parameter when defining a gremlin has to be an object providing the static members of the gremlin!")


class Gremlin extends Parent
constructor: ->
super
constructor.call this

util.Helper.mixin Gremlin, instanceMembers
Gremlin[key] = member for own key, member of staticMembers

return Gremlin

@extend: (constructor, instanceMembers, staticMembers) ->
define @, constructor, instanceMembers, staticMembers

# @property [Object] the data object holding the dom element's data attributes
data: null
el: null
id: null
klass: null


# The constructor function used internally to instantiate gremlins.
#
#
Expand Down
32 changes: 1 addition & 31 deletions src/scripts/gremlinDefinitions/Pool.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
goog.provide 'gremlinDefinitions.Pool'

goog.require 'util.Helper'
goog.require 'gremlinDefinitions.Gizmo'
goog.require 'modules.ModuleCollection'
Expand All @@ -22,44 +23,13 @@ class gremlinDefinitions.Pool
modules.ModuleCollection.extendGizmo name, Definition
definitions[name] = Definition

define: (name, constructor, instanceMembers, staticMembers) ->
unless typeof name is 'string'
throw new Error("The first parameter when defining a gremlin has to be a string, the gremlin definition's name!")

unless typeof constructor is 'function'
throw new Error("The second parameter when defining a gremlin has to be the constructor function!")

unless instanceMembers is undefined or typeof instanceMembers is 'object'
throw new Error("The third parameter when defining a gremlin has to be an object providing the instance members of the gremlin!")

unless staticMembers is undefined or typeof staticMembers is 'object'
throw new Error("The fourth parameter when defining a gremlin has to be an object providing the static members of the gremlin!")


#constructor = noop if typeof constructor is 'object'

class Gremlin extends gremlinDefinitions.Gizmo
constructor: ->
super
constructor.call this

Gremlin::klass = Gremlin

util.Helper.mixin Gremlin, instanceMembers
Gremlin[key] = member for own key, member of staticMembers

@set name, Gremlin
return Gremlin

addClass: (name, Gremlin) ->
unless typeof name is 'string'
throw new Error("Please provide the name of the gremlin!")

unless typeof Gremlin is 'function'
throw new Error("When adding a gremlin, you have to provide a constructor function!")

Gremlin::klass = Gremlin

@set name, Gremlin
return Gremlin

Expand Down
2 changes: 1 addition & 1 deletion src/scripts/modules/ModuleCollection.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class modules.ModuleCollection
module.extend Gizmo for module in modules

@bindGizmo: (name, gizmo) ->
modules = getModules name, gizmo.klass
modules = getModules name, gizmo.constructor
module.bind gizmo for module in modules


3 changes: 0 additions & 3 deletions src/scripts/namespace.coffee

This file was deleted.

6 changes: 2 additions & 4 deletions src/scripts/packages/Package.coffee
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
goog.provide 'packages.Package'

goog.require 'namespace'

class packages.Package

root = namespace
root = {}

getNamespace = (name, content = null) ->
items = name.split '.'
Expand All @@ -19,4 +17,4 @@ class packages.Package
return new packages.Package arguments... if this not instanceof packages.Package
@_package = getNamespace ns, content

@get: (ns) -> getNamespace ns
@require: (ns) -> getNamespace ns
12 changes: 12 additions & 0 deletions test/js/gremlins/cs/InheritTest.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class window.InheritTestParent extends G.Gizmo
@FOO: 'FOO'
constructor : ->
super

foo: ->

bar: 'bar'

class window.InheritTestChild extends window.InheritTestParent
constructor: ->
super
38 changes: 38 additions & 0 deletions test/js/gremlins/cs/InheritTest.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions test/js/gremlins/cs/InheritTest.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": 3,
"file": "InheritTest.js",
"sourceRoot": "",
"sources": [
"InheritTest.coffee"
],
"names": [],
"mappings": ";AAAA;CAAA,KAAA;oSAAA;;CAAA,CAAM,IAAM;CACV;;CAAA,EAAA,CAAA,CAAA,YAAC;;CACa,EAAA,CAAA,uBAAA;CACZ,KAAA,GAAA,2CAAA;CAFF,IACc;;CADd,EAIA,MAAK;;CAJL,EAMA,EANA;;CAAA;;CADqC;;CAAvC,CASM,IAAM;CACV;;CAAa,EAAA,CAAA,sBAAA;CACX,KAAA,GAAA,0CAAA;CADF,IAAa;;CAAb;;CADoC,KAAM;CAT5C"
}
Loading

0 comments on commit 67be65c

Please sign in to comment.