Coder Social home page Coder Social logo

activejs's Introduction


Pragmatic, Reactive State Management for JavaScript Apps

npm i @activejs/core

⚡ Quick Example

This is how an implementation of a simple counter looks like, using a NumUnit, one of the reactive data structures that ActiveJS provides. The NumUnit stores and provides a number value at all times ensuring the type-safety.

// initialize a reactive data structure to store numbers
const counter = new NumUnit(); // with default initial-value 0

// two pure functions to produce an appropriate new value
const increment = value => value + 1;
const decrement = value => value - 1;

// subscribe for reactive value access, and log the value
counter.subscribe(value => console.log(value));
// immediately logs 0, and will log any future values

// increment
counter.dispatch(increment); // you'll see 1 in the console
// the pure function is called with the current value and
// the returned value is dispatched automatically

// decrement
counter.dispatch(decrement); // you'll see 0 in the console
// that's it our counter is complete

// you can also access the value directly
console.log(counter.value()); // logs 0

📊 Quick Comparisons

A simple "counter" implemented in Redux vs ActiveJS.



A simple "counter" implemented in NgRx vs ActiveJS.

🤝 Contributing

We welcome all contributions, whether you're reporting an issue, helping us fix bugs, improve the docs, or spread the word. We also welcome your suggestions and feedback.

⚖ Licence

MIT

💻 Author

Ankit Singh

activejs's People

Contributors

dabalyan avatar

Stargazers

Klaus Ferreira avatar Cameron Phillips avatar Vijay Makhija avatar ʟᴊᴜɴɢᴍ•ʀᴋ avatar Amaury Borges Souza avatar Michael Floering avatar Jeremy Dombrowski avatar Tyler Sustare avatar Felipe Gustavo avatar Reyk Carstens avatar Can Burak Sofyalıoğlu avatar Duncan avatar Gabriel Guerreiro avatar  avatar Ajit Fawade avatar Heartlander avatar Milad Kawas avatar jay avatar Jacob Beltran avatar koppt avatar Sylvain Favé avatar  avatar YGZX avatar Rinat Valiullov avatar Neoxn3il avatar Ragland Asir avatar Yamil Lanz avatar Ángel Herrador avatar Luis Bedoya avatar Chris Michael avatar stefanovualto avatar Parmesh Krishen avatar Emil Bellmann avatar Jaime Tobalina avatar Haitam avatar Phil Gemellas avatar Thomas Gty avatar Matheus Felipe avatar  avatar  avatar Nicco avatar Luis Martinez Suarez avatar Rythz Lab avatar EmonHR avatar Fayez NACCACHE avatar Sarvesh Dubey avatar Ernst Salzmann avatar Rajan Prasad avatar Yoav Ganbar avatar Simon Peters avatar Chris C avatar Ben Lemaitre avatar Ankita Saloni avatar  avatar Michele Riva avatar Brandon Orther avatar Eduardo Diosdado avatar Cole Townsend avatar Israel Flores avatar Nattapon Pondongnok avatar marco gazzuolo avatar Roman Hossain Shaon avatar Tomáš Hübelbauer avatar Reda Benchraa avatar Sunny Singh avatar Ben Rogerson avatar kevinnguyenai avatar Carlos avatar Muhammad Farid Zia avatar Sakar SR avatar Pratik Chaudhari avatar Tiago avatar Dirk Porsche avatar  avatar  avatar Raí Siqueira avatar Lasitha Denipitiya avatar Kiran Jd avatar  avatar zhongzhong avatar Daisuke Suzuki avatar  avatar Pedro Carneiro avatar Kernel Soe avatar Yurii Timofeev avatar Sylvain LE GLEAU avatar Matt Vanderpol avatar Emmanuel Salomon avatar Pawan Kumar avatar Karan Pratap Singh avatar Victor Martins avatar Andréas Hanss avatar dami avatar Alessandro Giordo avatar Gilmar Souza avatar MickGe avatar Ruslan Voroshchuk avatar Dmitry Polushkin avatar Eros Valzasina avatar Dima Beglov avatar

Watchers

James Cloos avatar Josh Tate avatar  avatar Jason Sultana avatar

activejs's Issues

DictUnit not persisting to local storage and subscribing after dispatching not working

Describe the bug
I have the following angular service

<dx-form [colCount]="2">
		<dxi-item>
			<div *dxTemplate>
				<pim-select
					(selection)="genderSelection($event)"
					[dataSource]="genderUrl"
					[grouped]="false"
					[placeholder]="'Gender *'"
				></pim-select>
			</div>
		</dxi-item>
</dx-form>


import { Injectable } from '@angular/core'
import { DictUnit } from '@activejs/core'

@Injectable({
	providedIn: 'root',
})
export class RegistrationState {
	private _dictionaryUnit = new DictUnit({
		id: 'registration',
		// immutable: true,
		persistent: true,
		cacheSize: 200,
		// initialValue: {},
		distinctDispatchCheck: true,
	})

	get dictUnit() {
		return this._dictionaryUnit
	}
}

class Stats {
	constructor(
		private _regState: RegistrationState,
	) {}

        ngOnInit(): void { }

	genderSelection(e: Record<string, string>) {
               console.log{e} // e IS CORRECTLY PRINTED
		this._regState.dictUnit.dispatch('gender', e)  // NO LOCAL STORAGE
	}
}


export class InfoComponent implements OnInit {
    constructor(private _regState: RegistrationState) {}

	ngOnInit(): void {
	   this._regState.dictUnit.subscribe((gender) => {
			console.log('gender: ', { gender })  // NOTHING IS LOGGED
		})
	}

}

To Reproduce
Steps to reproduce the behavior:

Expected behavior
The dispatched data should be persisted to local storage and printed in the subscription

Screenshots
If applicable, add screenshots to help explain your problem.

activejs-local-storage

Environment (please complete the following information):

  • OS: [Linux Mint]
  • Browser [Chrome]
  • ActiveJS Version ["@activejs/core": "^0.2.3",]

Additional context
Add any other context about the problem here.
"@angular/cli": "^12.0.2",
"rxjs": "~6.6.7"

Abandoned repo?

Has development stopped in this repo? I would like to use it but it seems to have been abandoned?

activejs/core NOT compatible with rxjs 7.1.0

Describe the bug
A clear and concise description of what the bug is.
I am using activejs/core in my application. I update to rxjs 7.1.0. After, everywhere I use .subscribe errors are generated

To Reproduce
Steps to reproduce the behavior:

  1. Create a DictUnit (using rxjs 6.*)
  2. add a key/value property
  3. Subscribe and prine the value of the property
  4. Update to rxjs 7.1.0
  5. Attempt to serve the app - the errors are generated in the console.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS: [e.g. iOS]
  • Browser chrome
  • ActiveJS Version [e.g. 0.2.3]

Additional context
Add any other context about the problem here.

Docs Calrity

In the cases where the Docs reference the value of a unit they seem a little misleading

StringUnit can not be used as a drop-in replacement for primitive string value, since StringUnit is a non-primitive data structure, and the actual string value is stored inside as Unit.value property. See the below comparisons for more clarity.

unit.value does not seem to be a getter, which would have it behave as a property -- rather it's a function that returns the value, which makes it a method.

perhaps?

StringUnit can not be used as a drop-in replacement for primitive string value, since StringUnit is a non-primitive data structure. The contained string value within the StringUnit is accessed via the Unit.value() method. See the below comparisons for more clarity.

Custom Persistence (per Unit persistence) - Idea/Proposal/Question?

So I just wanted to ask if Activejs could/would support:

  1. Custom Persistent Storage
    Something along the lines of providing an interface (get, set, observe...) which then a developer can provide and handle things like serialization, maybe even initial values etc. themselves. More specifically for example an IndexedDB wrapper might be interesting - here serialization for example would not have to (and should not) be done.

  2. Storage Specification per Unit Type
    Following the first point, it would be nice to specify this storage interface per unit (not sure if that's already/or even possible - since it needs to be set during configuration of Activejs I assume it isn't). This way one could for example save an "image blob list" unit in the more performant (and serialization-free) IndexedDB and some other smaller units (for example list of updogs) in eg. a synchronizable (and serialized) extension storage (browser.storage.sync this is specific to browser extensions).

Both of these could be done by not using Activejs' persistence, and instead listening on the object changes and saving them ourselves.

Would this observer approach instead be the recommended way to go?
Or would/should the above 2 ideas (or one of them) be in the scope of Activejs?

What do you think?

Generally asking anyone (inside and outside the Activejs team) who's interested

Vue Integration

Hi,

first of all, I would like to say that activejs looks very promising. And the amount of work to produce such a library and the related documentation is impressive! Thank you for that!

I have to admit that I have limited time to investigate new libraries in my current job and we tend to use vuejs.

It would be great to have in the documentation an integration with vuejs to help to start using it.

Good job and keep going! 👍

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.