brodanoel / duix Goto Github PK
View Code? Open in Web Editor NEWA State Manager focused on KISS and Pareto's Principle
License: MIT License
A State Manager focused on KISS and Pareto's Principle
License: MIT License
Implement events. For example: "User just logged"
Should be implemented in some way like:
duix.event('USER_JUST_LOGGED'); // not sure if `duix.event` or `duix.dispatch`
duix.listen(‘USER_JUST_LOGGED’, callback);
By importing
import deepEqual from './utils/deepEqual';
The import does not work in browser, because the extension is not set.
Use instead:
import deepEqual from './utils/deepEqual.js';
const store = Object.create(null)
export default ((host = Object.create(null), subs = new Map()) => Object.assign(host, {
emit(event, ...data) {
if (subs.has(event)) for (const h of subs.get(event)) h.apply(null, data)
},
subscribe(event, handler) {
if (!(handler instanceof Function)) throw new TypeError('subs need functions')
if (!subs.has(event)) subs.set(event, new Set())
subs.get(event).add(handler)
return () => host.unsubscribe(event, handler)
},
unsubscribe (event, handler) {
if (!subs.has(event)) return
const ls = subs.get(event)
ls.delete(handler)
if (!ls.size) subs.delete(event)
},
set(key, val) {
const old = store[key]
if (old != null && old === val) return
host.emit(key, store[key] = val, old)
},
get: key => store[key]
}))()
If you are doing:
useEffect(() => {
duix.subscribe('user', setUser)
}, []);
The setUser
function is going to get old in the following render.
We have to find a way to keep it simple, but fix it.
I think we should not create a useDuix()
, because the idea is to keep DUIX as a state manager based on events.
Would travis be ok for you?
=> If yes, I can implement it, but you need to enable the integration
If no, tell me which one to use :-)
But is it a easy to understand name ?
See a beginning of discussion in #10
This, it is still maintained. There is just nothing to improve here.
Example from Expo
build.d.ts
declare enum BackgroundFetchResult {
NoData = 1,
NewData = 2,
Failed = 3
}
declare enum BackgroundFetchStatus {
Denied = 1,
Restricted = 2,
Available = 3
}
interface BackgroundFetchOptions {
minimumInterval?: number;
stopOnTerminate?: boolean;
startOnBoot?: boolean;
}
export declare function getStatusAsync(): Promise<BackgroundFetchStatus | null>;
export declare function setMinimumIntervalAsync(minimumInterval: number): Promise<void>;
export declare function registerTaskAsync(taskName: string, options?: BackgroundFetchOptions): Promise<void>;
export declare function unregisterTaskAsync(taskName: string): Promise<void>;
export { BackgroundFetchResult as Result, BackgroundFetchStatus as Status, };
I'm not saying is right or wrong, I'm just curious.
What about using Set for subscriber list, and Map for key => ... ?
Check what happens if we mutate the state. And define what should happens (should it be immutable?)
For example:
‘’’js
const x = duix.get(‘x’);
x.foo = ‘bar’;
‘’’
Document it
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.