# thor-rx

> ThorRx is a tiny Proxy based lib for deliverering events and change records to keep track of mutations on objects (models). When a property is modified on an thor-rx 'observed' instance thor-rx will deliver change notifications that helps you keep track

Latest version **0.0.3** (published 2017-04-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install thor-rx
pnpm add thor-rx
yarn add thor-rx
bun add thor-rx
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2017-04-10 |
| First published | 2017-03-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Magnus Thor |
| Maintainers | magnusthor |
| Keywords | ES6, observable, rx, tracking, typescript |

## Links

- npm: https://www.npmjs.com/package/thor-rx
- Repository: https://github.com/MagnusThor/thor-rx
- Homepage: https://github.com/MagnusThor/thor-rx#readme
- Issues: https://github.com/MagnusThor/thor-rx/issues
- npm.io page: https://npm.io/package/thor-rx

## Dependencies (1)

- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.10

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.3 (latest) — 2017-04-10
- 0.0.2 — 2017-03-31
- 0.0.1 — 2017-03-22

## README

# thor-rx
ThorRx is a tiny Proxy based lib for
deliverering events and change records to keep track of mutations on objects (models).
When a property is modified on an thor-rx 'observed' instance 
thor-rx will deliver change notifications 
that helps you keep track of changes in a smooth way.

## Installation

    npm install thor-rx


# Documentation

Below follows a brief documentation.

## ThorRx&lt;T extends ThorRxBase &gt;(obj:any, (changes:ChangeModel) =>void):ThorRx&lt;T&gt;

Create a new thor-rx observer

    let rx = new ThorRx<T>(instance,(changes:ChangeModel) => {}); 

### getObserver():T

Get a thor-rx instance of type T.  T is the proxied instances of yours. 

    observerOfT = rx.getObserver();


 #### example

 Where we have an object(Model) Person 

      let person = new Person();

      let rx = new ThorRx<T>(person , (changes:ChangeModel) => {
            // do op with changes
      }); 

      let rxPerson= rx.getObserver();

      // rx person is now a observed (Proxied) instance of Person


## ChangeModel

Change model contains information about the current change.

    class ChangeModel {
        target: any;
        type: string;
        newValue: any;
        oldValue: any;
        timeStamp: Date;
        constructor(target: any, type: string, newValue: any, oldValue: any);
        }

### Change type's

An change type can be as follows: add, removed and update.  
add and remove relates to Array properties. 


## ThorRxBase

The objects you wich to observe must derive (extends) from 
ThorRxBase.

     class MyModel extends ThorRxBase{
         constructor(){
             super(); 
             ..
         }
     }

### observe(target:any) : void

Make an property / target of the class that derives from ThorRxBase 
an observable. Will report changes when modified

### unobserve(target:any): void 

Makes a properry ( target) a non observable. Will not report changes when modified



# Decorators

Decorators lets you by decorating properties of your objects(classes)
gain control of what attributes that thor-rx captures mutations on.
By default the property is observed.

### @Observe(isObserve:boolean)

if an @Observe decorator exists on a property , you can control it
by settig isObserve:boolean to true/false, if fn:Function is
defined fn will be the Fn to be called on property mutations.

Note: will not affect newable properties. See observe and unobserve above.

#### example

    class Person{

        @Observe(false) fullName:string;
        @Observe(true) age:number
        ...
    }

# Example ( Quick guide )

The example below creates an thor-rx observer for Person (class) 

    let personObserver = new ThorRx<Person>(new Person(), (change:ChangeModel) => {
         // do op's with the change
    }); 

Where person look needs to extend ThorRxBase such as

    class Person extends ThorRxBase {
        fullName:string
        constructor(){
            super();
        }
    }    

To get an observer instance you need to call .getObserver():T such as below.

    let personObserver = new ThorRx<Person>(new Person(),(change:ChangeModel) => {
        // do op's with the change
    });

    let person =  personObserver.getObserver()

    person.fullName = "Sven Erik Magnusson";

Setting the property .fullName will deliver (fire) the changes 
handler you provded , in this example 

    (change:ChangeModel) => {

        // do op

    }

# Roadmap / Todo

    -

---
_Source: https://npm.io/package/thor-rx · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
