Skip to content

Instantly share code, notes, and snippets.

@a21ns1g4ts
Last active November 12, 2021 15:58
Show Gist options
  • Save a21ns1g4ts/4e1da15f08a1f51198bc8b63a9c298ef to your computer and use it in GitHub Desktop.
Save a21ns1g4ts/4e1da15f08a1f51198bc8b63a9c298ef to your computer and use it in GitHub Desktop.

Revisions

  1. a21ns1g4ts revised this gist Nov 12, 2021. No changes.
  2. a21ns1g4ts revised this gist Jul 20, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions zoologicMonitor.js
    Original file line number Diff line number Diff line change
    @@ -102,7 +102,7 @@ events = [
    ]

    agents = [
    {id: 0, name: "Escureto Mimoso", type: "cat"},
    {id: 1, name: "Barte Lamarin", type: 'cat'},
    {id: 0, name: "Escureto", type: "cat"},
    {id: 1, name: "Digous", type: 'cat'},
    {id: 2, name: "Atila Silva", type: 'person'}
    ]
  3. a21ns1g4ts revised this gist Jul 3, 2020. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions zoologicMonitor.js
    Original file line number Diff line number Diff line change
    @@ -96,13 +96,13 @@ function makeDog(obj = {}){
    }

    events = [
    {id : 0 , name: "walk" },
    {id : 1 , name: "sleep" },
    {id : 1 , name: "fly" },
    {id: 0, name: "walk"},
    {id: 1, name: "sleep"},
    {id: 1, name: "fly"},
    ]

    agents = [
    {id:0 , name : "Escureto Mimoso" , type: "cat"},
    {id:1 , name : "Barte Lamarin" , type: 'cat'},
    {id:2 , name : "Atila Silva" , type: 'person'}
    {id: 0, name: "Escureto Mimoso", type: "cat"},
    {id: 1, name: "Barte Lamarin", type: 'cat'},
    {id: 2, name: "Atila Silva", type: 'person'}
    ]
  4. a21ns1g4ts revised this gist Jul 3, 2020. 2 changed files with 26 additions and 19 deletions.
    15 changes: 10 additions & 5 deletions zoologicMonitor.html
    Original file line number Diff line number Diff line change
    @@ -2,12 +2,17 @@
    <script lang="javascript">
    const dog = makeDog(
    {
    name:"Laio" ,
    id: 1 ,
    name:"Laio",
    id: 1,
    }
    );
    dog.fly();
    dog.walk()

    const person = makePerson(Person.findPerson(2));
    person.walk();
    const person = makePerson(Person.find(2))
    person.sleep()

    const cat = makeCat(Cat.find(1))
    cat.walk()
    cat.fly()
    cat.sleep()
    </script>
    30 changes: 16 additions & 14 deletions zoologicMonitor.js
    Original file line number Diff line number Diff line change
    @@ -39,31 +39,32 @@ const Event = {
    return events[id]
    }
    }

    const Agent = {
    findAgent(id){
    find(id){
    return agents[id]
    },
    }
    const Person = Object.assign({
    findPerson(id){
    let agent = Agent.findAgent(id)
    if(agent.type === 'person')
    return agent
    }
    }, walkable)

    const Dog = Object.assign({} , walkable)

    const eventSender = Object.assign({
    emitEvent(event , agent){
    this.log(event , agent)
    }
    }, logable);

    const Person = Object.assign({
    find(id){
    let agent = Agent.find(id)
    if(agent.type === 'person')
    return agent
    }
    }, walkable)

    const Dog = Object.assign({} , walkable, sleepable)

    const Cat = Object.assign({
    findCat(id){
    let agent = Agent.findAgent(id);
    find(id){
    let agent = Agent.find(id);
    if(agent.type === 'cat')
    return agent
    }
    @@ -74,7 +75,7 @@ const makePerson = function (obj = {}){
    name: obj.name,
    id: obj.id,
    type: "person"
    }, Person)
    }, Person, sleepable)
    }

    const makeCat = function(obj = {}){
    @@ -92,7 +93,8 @@ function makeDog(obj = {}){
    type: "dog"
    }, Dog, flyable)

    };
    }

    events = [
    {id : 0 , name: "walk" },
    {id : 1 , name: "sleep" },
  5. a21ns1g4ts revised this gist Jul 3, 2020. 2 changed files with 30 additions and 34 deletions.
    15 changes: 6 additions & 9 deletions zoologicMonitor.html
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,13 @@
    <script src="zoologicMonitor.js"></script>
    <script lang="javascript">

    const dog1 = makeDog(
    const dog = makeDog(
    {
    name:"Mark Pure object" ,
    name:"Laio" ,
    id: 1 ,
    }
    );
    dog1.fly();
    dog.fly();

    const person1 = makePerson(Person.findPerson(2));

    person1.walk();

    </script>
    const person = makePerson(Person.findPerson(2));
    person.walk();
    </script>
    49 changes: 24 additions & 25 deletions zoologicMonitor.js
    Original file line number Diff line number Diff line change
    @@ -1,97 +1,96 @@
    const walkable = {
    walk(){
    eventSender.emitEvent(events[0] , {
    name: this.name , id: this.id , type: this.type
    });
    eventSender.emitEvent(events[0], {
    name: this.name, id: this.id, type: this.type
    })
    },
    }

    const sleepable = {
    sleep(){
    eventSender.emitEvent(events[1] , {
    name: this.name , id: this.id , type: this.type
    });
    name: this.name, id: this.id, type: this.type
    })
    }
    }

    const flyable = {
    fly(){
    eventSender.emitEvent(events[2] , {
    name: this.name , id: this.id , type: this.type
    });
    name: this.name, id: this.id, type: this.type
    })
    },
    }

    const logable = {
    log(event , agent){
    log(event, agent){
    console.log(`
    event: ${event.name};
    event_id: ${event.id};
    agent: ${agent.name};
    agent_id: ${agent.id};
    agent_type: ${agent.type}
    `);
    agent_type: ${agent.type};
    `)
    }
    }

    const Event = {
    findEvent(id){
    return events[id];
    return events[id]
    }
    }
    const Agent = {
    findAgent(id){
    return agents[id];
    return agents[id]
    },
    }
    const Person = Object.assign({
    findPerson(id){
    let agent = Agent.findAgent(id);
    let agent = Agent.findAgent(id)
    if(agent.type === 'person')
    return agent;
    return agent
    }
    } , walkable)
    }, walkable)

    const Dog = Object.assign({} , walkable);
    const Dog = Object.assign({} , walkable)

    const eventSender = Object.assign({
    emitEvent(event , agent){
    this.log(event , agent);
    this.log(event , agent)
    }
    } , logable);
    }, logable);


    const Cat = Object.assign({
    findCat(id){
    let agent = Agent.findAgent(id);
    if(agent.type === 'cat')
    return agent;
    return agent
    }
    }, walkable , flyable, sleepable);
    }, walkable, flyable, sleepable)

    const makePerson = function (obj = {}){
    return Object.assign({
    name: obj.name,
    id: obj.id,
    type: "person"
    },
    Person
    )
    }, Person)
    }

    const makeCat = function(obj = {}){
    return Object.assign({
    name : obj.name,
    id : obj.id,
    type : "cat"
    }, Cat );
    }, Cat)
    }

    function makeDog(obj = {}){
    return Object.assign({
    name: obj.name,
    id: obj.id,
    type: "dog"
    } , Dog , flyable)
    }, Dog, flyable)

    };
    events = [
  6. a21ns1g4ts renamed this gist Jun 30, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. a21ns1g4ts revised this gist Apr 18, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion zoologicMonitor.html
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    <script src="catMonitor.js"></script>
    <script src="zoologicMonitor.js"></script>
    <script lang="javascript">

    const dog1 = makeDog(
  8. a21ns1g4ts created this gist Dec 23, 2018.
    16 changes: 16 additions & 0 deletions zoologicMonitor.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    <script src="catMonitor.js"></script>
    <script lang="javascript">

    const dog1 = makeDog(
    {
    name:"Mark Pure object" ,
    id: 1 ,
    }
    );
    dog1.fly();

    const person1 = makePerson(Person.findPerson(2));

    person1.walk();

    </script>
    107 changes: 107 additions & 0 deletions zoologicoMonitor.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,107 @@
    const walkable = {
    walk(){
    eventSender.emitEvent(events[0] , {
    name: this.name , id: this.id , type: this.type
    });
    },
    }

    const sleepable = {
    sleep(){
    eventSender.emitEvent(events[1] , {
    name: this.name , id: this.id , type: this.type
    });
    }
    }

    const flyable = {
    fly(){
    eventSender.emitEvent(events[2] , {
    name: this.name , id: this.id , type: this.type
    });
    },
    }

    const logable = {
    log(event , agent){
    console.log(`
    event: ${event.name};
    event_id: ${event.id};
    agent: ${agent.name};
    agent_id: ${agent.id};
    agent_type: ${agent.type}
    `);
    }
    }

    const Event = {
    findEvent(id){
    return events[id];
    }
    }
    const Agent = {
    findAgent(id){
    return agents[id];
    },
    }
    const Person = Object.assign({
    findPerson(id){
    let agent = Agent.findAgent(id);
    if(agent.type === 'person')
    return agent;
    }
    } , walkable)

    const Dog = Object.assign({} , walkable);

    const eventSender = Object.assign({
    emitEvent(event , agent){
    this.log(event , agent);
    }
    } , logable);

    const Cat = Object.assign({
    findCat(id){
    let agent = Agent.findAgent(id);
    if(agent.type === 'cat')
    return agent;
    }
    }, walkable , flyable, sleepable);

    const makePerson = function (obj = {}){
    return Object.assign({
    name: obj.name,
    id: obj.id,
    type: "person"
    },
    Person
    )
    }

    const makeCat = function(obj = {}){
    return Object.assign({
    name : obj.name,
    id : obj.id,
    type : "cat"
    }, Cat );
    }

    function makeDog(obj = {}){
    return Object.assign({
    name: obj.name,
    id: obj.id,
    type: "dog"
    } , Dog , flyable)

    };
    events = [
    {id : 0 , name: "walk" },
    {id : 1 , name: "sleep" },
    {id : 1 , name: "fly" },
    ]

    agents = [
    {id:0 , name : "Escureto Mimoso" , type: "cat"},
    {id:1 , name : "Barte Lamarin" , type: 'cat'},
    {id:2 , name : "Atila Silva" , type: 'person'}
    ]