Comments (14)
Ah I believe it’s actually identify that can be called before init, which prevents fetching flags in init without the user, though I’ll add a note for the other calls like setTrait.
Yes batching traits and sending as an object would be useful, this is currently in our backlog.
I imagine it would something like
bulletTrain.setTraits({username:’abc’, otherProp’xyz’})
Edit: I’ve renamed the issue to something more actionable, I’ll keep this open until setTraits is done and can be called before init
from flagsmith-js-client.
Right, sorry yep I see, there was a couple conversations going on here. In future I'll try to limit these issues to 1 topic so we have something that's concise and actionable.
The latest release 0.1.1 of the JS and React Native clients include the following
- setTraits, allowing you to specify key value pairs for multiple traits, setting null as the value for any trait will remove the trait.
- calling setTrait and setTraits will not attempt a call to getFlags if it is called before bulletTrain.init
- documentation updated to describe how the above works.
I'll leave this issue open incase you guys have any feedback @davidskaarup @adenta @OscarGalindo.
from flagsmith-js-client.
No it wont @davidskaarup, this is intentional.
from flagsmith-js-client.
Hey @OscarGalindo Correct you can’t call setTrait before init, are you expecting to be able to? Or are you just wanting better error handling for this?
from flagsmith-js-client.
Actually will be fine if I can set everything before initialisation and then the client sdk only do 1 single request instead of 3-4 (one per trait + init).
But in any case, at least, the documentation should be fixed
Thanks!
from flagsmith-js-client.
Whats the progress on this? Every trait I set causes a rerender
from flagsmith-js-client.
Hey @adenta, will have a discussion with backend team about getting this progressed this evening. Thanks for being patient!
from flagsmith-js-client.
In this example in the documentation setTrait
is called before init
:
/*
Can be called both before or after you're done initialising the project.
Calling identify before will prevent flags being fetched twice.
*/
bulletTrain.identify("bullet_train_sample_user"}); //This will create a user in the dashboard if they don't already exist
bulletTrain.setTrait("favourite_colour","blue"); //This save the trait against the user, it can be queried with bulletTrain.getTrait
//Standard project initialisation
bulletTrain.init({
...
It also seems to work when I try it. Has there been updates since this conversation?
PS: We also really need a setTraits
function since having getFlags
called for every setTrait
is really bad.
from flagsmith-js-client.
In this example in the documentation
setTrait
is called beforeinit
:/* Can be called both before or after you're done initialising the project. Calling identify before will prevent flags being fetched twice. */ bulletTrain.identify("bullet_train_sample_user"}); //This will create a user in the dashboard if they don't already exist bulletTrain.setTrait("favourite_colour","blue"); //This save the trait against the user, it can be queried with bulletTrain.getTrait //Standard project initialisation bulletTrain.init({ ...
It also seems to work when I try it. Has there been updates since this conversation?
PS: We also really need asetTraits
function since havinggetFlags
called for everysetTrait
is really bad.
Yeah none of the conversation really affects this, identify will still not hit the api if it is called before init even after this PR.
RE setTraits, the new API piece is on our staging environment, I'll be doing some final testing against it in the next couple hours.
I'll then be releasing this under version 0.1.0 for both the JS and react-native clients.
from flagsmith-js-client.
Yeah none of the conversation really affects this, identify will still not hit the api if it is called before init even after this PR.
But it also calls setTrait
just after identify
, before init
, isn't that what the conversation is about?
RE setTraits, the new API piece is on our staging environment, I'll be doing some final testing against it in the next couple hours.
I'll then be releasing this under version 0.1.0 for both the JS and react-native clients.
That sounds great!
from flagsmith-js-client.
Thank you - I will try it out right away 👍
from flagsmith-js-client.
@kyle-ssg I have a quick question about setTraits
. In the documentation it says:
Setting a value of null for a trait will remove that trait.
Will that work the same way if the value is undefined
?
from flagsmith-js-client.
Going to close this, feel free to re-open if you guys have any issues.
from flagsmith-js-client.
setTrait is still unable to be called before init. It looks like it's expecting api to be set and throwing an error if it isn't. Should that code fallback to the default api value if init hasn't been called?
from flagsmith-js-client.
Related Issues (20)
- Case sensitive flags are lower cased when trying to retrieve values
- isLoading never updates to false if flag is disabled (React useFlagsmith hook) HOT 5
- Clear cache when calling logout() HOT 5
- the value obtained is sometimes not appropriate HOT 2
- Don't call getFlags() if the identity set is the same HOT 6
- error TS2304: Cannot find name 'bool'
- Provide explicit setter functions for Data Dog / Dynatrace HOT 1
- Improve useFlagsmithLoading
- Cannot read properties of null (reading 'getValue') HOT 4
- isLoading never updates to false HOT 2
- Flagsmith's `loadingState.error` is not respect actual error state HOT 11
- [Bug] - NextJS >= 13.0.0 SSR `useFlagsmith` state not matching the state that is passed to the provider. HOT 16
- flagsmith/react only works in React 18 HOT 3
- [Bug] - TypeError: Cannot read properties of null (reading 'getValue') HOT 5
- Flagsmith's 'useFlags' doesn't return actual cached flags when request failed HOT 2
- Rollup Name for react HOT 5
- Inconsistent license information HOT 2
- Caching with multiple instance doesn't work HOT 6
- Typing issue in react.tsx: 'flagsmith' is possibly 'null' HOT 3
- useFlags() race condition HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flagsmith-js-client.