By the way, I would prefer using Ak47 over Object.observe for some
cases (if there isn't a significant performance issue). ak47 is not
only for object properties, it's also for observing variables;

> var birthdate = ak47(new Date("1.1.1990")),
       age = ak47(birthdate, today, function(bd, td){
         return parseInt( (td - bd) / 31536000000 );
       });

> age()
22

It ensures all data structures are observable. And it's fairly simpler
than JavaScript's new accessor and observation APIs.

Here is a use case, assume we have a module like below:

// a.js

var foo = "hello",
       bar = hello + "  world";

module.exports = {
  foo: foo,
  bar: bar
};

// b.js
var a = require('./a');

a.foo = "What's up?"

console.log(a.foo); // what's up?
console.log(a.bar);  // hello world

When we ignore using classes (or another way to create properties) in
CommonJS modules, we may have two copies of what we export from a
module. One is internal, the other one is external when a client
module overrides the property.

To solve this issue, I was creating properties like below:

var foo = (function(){

  var value = undefined;

   return function foo(newValue){
     if(arguments.length){
       value = newValue;
     }

     return value;
   };

}());

And after using this pattern for long time, I came up to the the idea of ak47.

On Mon, Oct 29, 2012 at 5:42 PM, Rick Waldron <[email protected]> wrote:
> Related... v8 just landed support for Object.observe()
>
> -Rick
>
> On Monday, October 29, 2012 at 8:11 PM, Azer Koçulu wrote:
>
> Hi All,
>
> I've created a new JS library for defining properties that can be subscribed
> for updates and can interact with eachother.
>
> Check it here;
>
> https://github.com/azer/ak47
>
> Readme contains many examples. Here is another one:
>
> var user = ak47({ name: 'joe', 'birthdate': 21 });
>
>> user.name()
> "joe"
>> user.name.subscribe(console.log);
>> user.name("mike")
> "mike"
> "mike" "joe"
>
> Defining a new property that observes another(s):
>
>> var greeting = ak47(joe.name, function(name){
> return 'Hello ' + name;
> });
>> greeting()
> "Hello mike"
>> joe.name("joe")
>> greeting()
> "Hello joe"
>
> What do you think?
>
> Azer
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to