1
0
Fork 0
Commit Graph

22 Commits (8b74ed9f1b0261ec99fbd3fb0cc212a1e953aece)

Author SHA1 Message Date
Mike Gerwitz d84b86b21b
Added `proxy' keyword support
The concept of proxy methods will become an important, core concept in ease.js
that will provide strong benefits for creating decorators and proxies, removing
boilerplate code and providing useful metadata to the system. Consider the
following example:

  Class( 'Foo',
  {
      // ...

      'public performOperation': function( bar )
      {
          this._doSomethingWith( bar );
          return this;
      },
  } );

  Class( 'FooDecorator',
  {
      'private _foo': null,

      // ...

      'public performOperation': function( bar )
      {
          return this._foo.performOperation( bar );
      },
  } );

In the above example, `FooDecorator` is a decorator for `Foo`. Assume that the
`getValueOf()` method is undecorated and simply needs to be proxied to its
component --- an instance of `Foo`. (It is not uncommon that a decorator, proxy,
or related class will alter certain functionality while leaving much of it
unchanged.) In order to do so, we can use this generic, boilerplate code

  return this.obj.func.apply( this.obj, arguments );

which would need to be repeated again and again for *each method that needs to
be proxied*. We also have another problem --- `Foo.getValueOf()` returns
*itself*, which `FooDecorator` *also* returns.  This breaks encapsulation, so we
instead need to return ourself:

  'public performOperation': function( bar )
  {
      this._foo.performOperation( bar );
      return this;
  },

Our boilerplate code then becomes:

  var ret = this.obj.func.apply( this.obj, arguments );
  return ( ret === this.obj )
      ? this
      : ret;

Alternatively, we could use the `proxy' keyword:

  Class( 'FooDecorator2',
  {
      'private _foo': null,

      // ...

      'public proxy performOperation': '_foo',
  } );

`FooDecorator2.getValueOf()` and `FooDecorator.getValueOf()` both perform the
exact same task --- proxy the entire call to another object and return its
result, unless the result is the component, in which case the decorator itself
is returned.

Proxies, as of this commit, accomplish the following:
  - All arguments are forwarded to the destination
  - The return value is forwarded to the caller
    - If the destination returns a reference to itself, it will be replaced with
      a reference to the caller's context (`this`).
  - If the call is expected to fail, either because the destination is not an
    object or because the requested method is not a function, a useful error
    will be immediately thrown (rather than the potentially cryptic one that
    would otherwise result, requiring analysis of the stack trace).

N.B. As of this commit, static proxies do not yet function properly.
2012-05-03 09:49:22 -04:00
Mike Gerwitz cdbcada4d2 Copyright year update 2011-12-23 00:09:11 -05:00
Mike Gerwitz 0739f983c7 Quoting keyword for consistency and to avoid potential minification issues 2011-12-22 23:40:39 -05:00
Mike Gerwitz 17047b53e9 Getters/setters will now trigger warnings if attempting to override without super getter/setter 2011-12-22 23:36:15 -05:00
Mike Gerwitz bcb0bcbe80 Added static validations for getters/setters 2011-12-22 23:36:15 -05:00
Mike Gerwitz db84c6fc6e Added virtual and override restrictions to getters/setters 2011-12-22 23:36:12 -05:00
Mike Gerwitz 9942ac9743 const getters/setters are unsupported (simply omit the setter) 2011-12-22 22:48:17 -05:00
Mike Gerwitz 4ada84e3b7 Abstract getters/setters are not yet supported
- Perhaps in future versions. The implementation details will not be ironed out before v0.1.0 and we can easily add it in the future without breaking BC. Getters/setters have not had too much attention thusfar in ease.js due to testing with systems that must work across many environments, including pre-ES5.
2011-12-22 22:46:02 -05:00
Mike Gerwitz e0254f6441 Removed invalid @package tags
Not a valid tag in jsdoc
2011-12-06 20:19:31 -05:00
Mike Gerwitz e41495c0d1 Added private member name conflict validations 2011-12-03 00:38:41 -05:00
Mike Gerwitz 8bcd55dbbb MemberBuilderValidator will now throw a warning if 'override' keyword is used without a super method 2011-11-05 11:58:12 -04:00
Mike Gerwitz 1fa92d44a1 [#25] Added Getter/Setter validator call tests for MemberBuilder 2011-11-05 09:40:58 -04:00
Mike Gerwitz 4e2af2333d [#25] Now injecting MemberBuilderValidator into MemberBuilder 2011-11-02 23:28:23 -04:00
Mike Gerwitz 3912f2d369 [#25] Began refactoring test-class_builder-static into new test case system 2011-11-02 23:23:13 -04:00
Mike Gerwitz b063a91e40 [#25] Added visibility de-escalation and escalation tests to MemberBuilderValidator for getters/setters 2011-10-30 12:06:09 -04:00
Mike Gerwitz 93021f3dbc [#25] Moved getter/setter validation tests into new test case
Much more elegant a test case now.
2011-10-28 00:22:50 -04:00
Mike Gerwitz ad0343fb9b [#25] Moved getter/setter validation logic into MemberBuilderValidator
- Tests have not yet been moved
2011-10-28 00:08:22 -04:00
Mike Gerwitz 625f62bbf1 [#25] Moved MemberBuilderValidator property tests into new test case 2011-10-23 01:14:13 -04:00
Mike Gerwitz a91cb01998 [#25] Moved MethodBuilder property validation into MemberBuilderValidator
- Tests have not yet been moved
2011-10-23 00:43:08 -04:00
Mike Gerwitz a5e2a507f2 [#25] Throwing error instead of method hiding; will implement in future 2011-10-22 13:57:17 -04:00
Mike Gerwitz 6e7e031ff9 [#25] [#25] Re-added accidently removed portion of test 2011-10-22 11:06:03 -04:00
Mike Gerwitz f9b951ddb2 [#25] [#25] Began moving MemberBuilder validation rules into MemberBuilderValidator (moved method rules) 2011-10-22 01:00:45 -04:00