-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixes #6. Properties on targets can now be deleted declaratively. * API is now P, S, PS, D (was patch, scope, ps). Terse capital initials are more consistently identifiable, at a skim, as directives in arbitrary code structures.
- Loading branch information
1 parent
0b0e889
commit c077856
Showing
3 changed files
with
111 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,40 @@ | ||
function patch(target){ | ||
function P(target){ | ||
for(var i = 1; i < arguments.length; i++) | ||
for(var key in arguments[i]) | ||
if(arguments[i].hasOwnProperty(key)) | ||
target[key] = ( | ||
arguments[i][key] instanceof scope | ||
arguments[i][key] == D | ||
? delete target[key] | ||
: target[key] = | ||
arguments[i][key] instanceof S | ||
? arguments[i][key].apply(target[key]) | ||
: arguments[i][key] | ||
) | ||
|
||
return target | ||
} | ||
|
||
function scope(closure){ | ||
if(!(this instanceof scope)) | ||
return new scope(closure) | ||
function S(closure){ | ||
if(!(this instanceof S)) | ||
return new S(closure) | ||
|
||
this.apply = function(definition){ | ||
return closure(definition) | ||
} | ||
} | ||
|
||
function ps(target, input){ | ||
return arguments.length === 2 | ||
? new scope(function(definition){ | ||
return patch(target, definition, input) | ||
}) | ||
: new scope(function(definition){ | ||
return patch(definition, target) // `target` really is `input` in that case | ||
}) | ||
function PS(target, input){ | ||
return new S( | ||
arguments.length === 2 | ||
? function(definition){ | ||
return P(target, definition, input) | ||
} | ||
: function(definition){ | ||
return P(definition, target) | ||
} | ||
) | ||
} | ||
|
||
function D(){} | ||
|
||
try { | ||
module.exports = {patch: patch, scope: scope, ps: ps} | ||
module.exports = {P: P, S: S, PS: PS, D: D} | ||
} catch(e) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters